如果xml没有子父结构,如何以所需格式解析此xml

时间:2015-01-09 06:19:56

标签: php xml xml-parsing

我有一个下面给出的xml。我应该如何解析这个,以便我可以存储在数组中,以便在下面的结构中显示它。

需要首先显示组规格,然后显示每个组的标题和值。

例如

group title          Specidentifier  Specvalue 

Audi specifications   Power           5w x 2
                      Maximum SPL     –90 dB
                      ..........      ......

General Specifications Battery type   11.1 V, 2500 mAh Lithium
                       Power Max      54 M Maximum               

下面是xml。我试过把它转换成数组。但是对我来说很难,因为这个标签(product_spec_identifier1)在每个组下重复。

<product_published_start>31-07-2013</product_published_start>
<product_published_end>31-07-2013</product_published_end>
<product_spec_group1>Audio Specifications</product_spec_group1>
<product_spec_identifier1>Power</product_spec_identifier1>
<product_spec_value1>65W x 2</product_spec_value1>
<product_spec_value1_language>en</product_spec_value1_language>
<product_spec_identifier2>Maximum SPL</product_spec_identifier2>
<product_spec_value2>–90 dB</product_spec_value2>
<product_spec_value2_language>en</product_spec_value2_language>
<product_spec_identifier3>Slew rate</product_spec_identifier3>
<product_spec_value3>40V/μsec</product_spec_value3>
<product_spec_value3_language>en</product_spec_value3_language>
<product_spec_identifier4>Sensitivity/impendance</product_spec_identifier4>
<product_spec_value4>250mV/46k ohms</product_spec_value4>
<product_spec_value4_language>en</product_spec_value4_language>
<product_spec_identifier5>Dynamic Range adjustment</product_spec_identifier5>
<product_spec_value5>90dB</product_spec_value5>
<product_spec_value5_language>en</product_spec_value5_language>
<product_spec_identifier6>Type</product_spec_identifier6>
<product_spec_value6>Multimedia Speakers</product_spec_value6>
<product_spec_value6_language>en</product_spec_value6_language>
<product_spec_identifier7>Frequency Response</product_spec_identifier7>
<product_spec_value7>60 Hz – 20 kHz</product_spec_value7>
<product_spec_value7_language>en</product_spec_value7_language>
<product_spec_identifier8>Signal-to-Noise Ratio</product_spec_identifier8>
<product_spec_value8>dB</product_spec_value8>
<product_spec_value8_language>en</product_spec_value8_language>
<product_spec_group2>General Specifications</product_spec_group2>
<product_spec_identifier1>Battery type</product_spec_identifier1>
<product_spec_value1>11.1 V, 2500 mAh Lithium</product_spec_value1>
<product_spec_value1_language>en</product_spec_value1_language>
<product_spec_identifier2>Power Max</product_spec_identifier2>
<product_spec_value2>54 M Maximum</product_spec_value2>
<product_spec_value2_language>en</product_spec_value2_language>
<product_spec_identifier3>Power requirement</product_spec_identifier3>
<product_spec_value3>100 – 240V AC, 50/60Hz</product_spec_value3>
<product_spec_value3_language>en</product_spec_value3_language>
<product_spec_identifier4>Dimensions (H x W x D)</product_spec_identifier4>
<product_spec_value4>300 mm X 164 mm x 275 mm</product_spec_value4>
<product_spec_value4_language>en</product_spec_value4_language>
<product_spec_identifier5>Weight</product_spec_identifier5>
<product_spec_value5>2,7 Kg</product_spec_value5>
<product_spec_value5_language>en</product_spec_value5_language>
<product_spec_identifier6>Dimensions: Subwoofer (H x W x D – Metric/English)</product_spec_identifier6>
<product_spec_value6>345 mm x 222 mm x 325 mm</product_spec_value6>
<product_spec_value6_language>en</product_spec_value6_language>
<product_spec_identifier7>Colour</product_spec_identifier7>
<product_spec_value7>Black</product_spec_value7>
<product_spec_value7_language>en</product_spec_value7_language>

1 个答案:

答案 0 :(得分:0)

使用xslt执行此操作检查w3学校的xslt示例