XML : How to display it as title and value for the xpath

Below is the xml.

  <product_spec_group1>Device Compatibility</product_spec_group1>  <product_spec_identifier1>BluetoothCompat_HK_US</product_spec_identifier1>  <product_spec_value1/>  <product_spec_value1_language>de</product_spec_value1_language>  <product_spec_group2>General Specifications</product_spec_group2>  <product_spec_identifier1>Power Consumption</product_spec_identifier1>  <product_spec_value1>65W (maximum); 0.5W (standby mode)</product_spec_value1>  <product_spec_value2_language>de</product_spec_value2_language>  <product_spec_group3>Audio Specifications</product_spec_group3>  <product_spec_identifier1>Input Impedance</product_spec_identifier1>  <product_spec_value1>>10k ohms</product_spec_value1>  <product_spec_value3_language>de</product_spec_value3_language>  <product_spec_group3>Audio Specifications</product_spec_group3>  <product_spec_identifier2>Frequency Response</product_spec_identifier2>  <product_spec_value2>40Hz – 20kHz</product_spec_value2>  <product_spec_value3_language>de</product_spec_value3_language>  <product_spec_group3>Audio Specifications</product_spec_group3>  <product_spec_identifier3>Signal-to-Noise Ratio</product_spec_identifier3>  <product_spec_value3>>85dB</product_spec_value3>  <product_spec_value3_language>de</product_spec_value3_language>  <product_spec_group3>Audio Specifications</product_spec_group3>  <product_spec_identifier4>Drivers</product_spec_identifier4>  <product_spec_value4>Two Ridge and two Atlas transducers</product_spec_value4>  <product_spec_value3_language>de</product_spec_value3_language>  <product_spec_group3>Audio Specifications</product_spec_group3>  <product_spec_identifier5>Power</product_spec_identifier5>  <product_spec_value5>  Tweeters: 2 x 15 watts @ 1% THD Woofers: 2 x 30 watts @ 1% THD  </product_spec_value5>  <product_spec_value3_language>de</product_spec_value3_language>  <product_spec_group3>Audio Specifications</product_spec_group3>  <product_spec_identifier6>Input Sensitivity</product_spec_identifier6>  <product_spec_value6>250mV</product_spec_value6>  <product_spec_value3_language>de</product_spec_value3_language>    

I want to display the output as
Device COmpatibility
Bluetooth - value
General specifications
Power consumption - 65W (maximum); 0.5W (standby mode)
Audio specifications
Frequency response - 40hz -20khz
signal-to-Noise ratio - 85db
Drivers two ridge and two atlas transducers ....likw wise.

i have tried below. But it does not give desired output.

  $i = 1;          $spec_title = array();          $spec_value = array();          $j=1;          $k=0;          $l=1;          foreach($xml->children() as $product_element)          {                  if(trim((string)$product_element->getName())=='product_spec_group'.$l)              {                    $key_value = trim((string)$product_element);                  $k++;                  $j=1;                  $x=0;                  $l++;                  }                    if($product_element->getName()=='product_spec_identifier'.$j)              {                     $x++;              $spec_title[$key_value][$x]['product_spec_identifier'] = trim((string)$product_element);              if(!strlen(trim((string)$xml->{'product_spec_value'.$j})))              $j++;                }              if($product_element->getName()=='product_spec_value'.$j)              {                  $spec_title[$key_value][$x]['product_spec_value'] = trim((string)$product_element);                  if(!strlen(trim((string)$xml->{'product_spec_value'.$j.'_language'})))                  $j++;                }              if($product_element->getName()=='product_spec_value'.$j.'_language')              {                  $spec_title[$key_value][$x]['product_spec_language'] = trim((string)$product_element);                  $j++;              }              }    

No comments:

Post a Comment