我想解析一个特定的 XML 提要,但我使用 SIMPLEXML 得到空值
任何帮助将不胜感激。
这是 Trovit XML 提要的一个示例。
例如,我像这样使用以下文件:
$xml = simplexml_load_file('myfile.xml'); print_r($xml);
<?xml version="1.0" encoding="utf-8"?>
<trovit>
<ad>
<id><![CDATA[7004578]]></id>
<url><![CDATA[http://www.yourdomain.co.uk/ad/7004578]]></url>
<title><![CDATA[2008 Toyota Prius Hybrid]]></title>
<content><![CDATA[111 Cruise control, Climate control, Front passenger airbag and
side airbags, Front and rear head airbags, Anti-lock brakes, Traction control, Remote central
door locking, Remote control alarm, Immobiliser, Front and rear electric windows, 16" alloy
wheels, Front fog lights, Radio cassette and CD autochanger, Steering wheel mounted controls,
Body coloured bumpers, Electric doormirrors.]]></content>
<price><![CDATA[10000]]></price>
<make><![CDATA[Toyota]]></make>
<model><![CDATA[Prius]]></model>
<color><![CDATA[Metallic Grey]]></color>
<year><![CDATA[2008]]></year>
<city><![CDATA[Bristol]]></city>
<city_area><![CDATA[Bristol]]></city_area>
<postcode><![CDATA[]]></postcode>
<region><![CDATA[Bristol]]></region>
<mileage unit="kilometers"><![CDATA[10000]]></mileage>
<doors><![CDATA[5]]></doors>
<fuel><![CDATA[petrol/ hybrid]]></fuel>
<transmission><![CDATA[manual]]></transmission>
<engine_size><![CDATA[1781]]></engine_size>
<power><![CDATA[75]]></power>
<seats><![CDATA[5]]></seats>
<gears><![CDATA[6]]></gears>
<pictures>
<picture>
<picture_url><![CDATA[http://www.yourdomain.co.uk/image1.jpg]]></picture_url>
<picture_title><![CDATA[front]]></picture_title>
</picture>
<picture>
<picture_url><![CDATA[http://www.yourdomain.co.uk/image2.jpg]]></picture_url>
<picture_title><![CDATA[interior]]></picture_title>
</picture>
</pictures>
<date><![CDATA[20/01/2011 14:30]]></date>
<is_new><![CDATA[0]]></is_new>
<car_type><![CDATA[hatchback]]></car_type>
<warranty><![CDATA[until 2011]]></warranty>
</ad>
<ad>
<id><![CDATA[7004579]]></id>
<url><![CDATA[http://www.yourdomain.co.uk/ad/7004578]]></url>
<title><![CDATA[2008 Toyota Prius Hybrid]]></title>
<content><![CDATA[222 Cruise control, Climate control, Front passenger airbag and
side airbags, Front and rear head airbags, Anti-lock brakes, Traction control, Remote central
door locking, Remote control alarm, Immobiliser, Front and rear electric windows, 16" alloy
wheels, Front fog lights, Radio cassette and CD autochanger, Steering wheel mounted controls,
Body coloured bumpers, Electric doormirrors.]]></content>
<price><![CDATA[210000]]></price>
<make><![CDATA[Toyota]]></make>
<model><![CDATA[Prius]]></model>
<color><![CDATA[Metallic Grey]]></color>
<year><![CDATA[2008]]></year>
<city><![CDATA[Bristol]]></city>
<city_area><![CDATA[Bristol]]></city_area>
<postcode><![CDATA[]]></postcode>
<region><![CDATA[Bristol]]></region>
<mileage unit="kilometers"><![CDATA[10000]]></mileage>
<doors><![CDATA[5]]></doors>
<fuel><![CDATA[petrol/ hybrid]]></fuel>
<transmission><![CDATA[manual]]></transmission>
<engine_size><![CDATA[1781]]></engine_size>
<power><![CDATA[75]]></power>
<seats><![CDATA[5]]></seats>
<gears><![CDATA[6]]></gears>
<pictures>
<picture>
<picture_url><![CDATA[http://www.yourdomain.co.uk/image1.jpg]]></picture_url>
<picture_title><![CDATA[front]]></picture_title>
</picture>
<picture>
<picture_url><![CDATA[http://www.yourdomain.co.uk/image2.jpg]]></picture_url>
<picture_title><![CDATA[interior]]></picture_title>
</picture>
</pictures>
<date><![CDATA[20/01/2011 14:30]]></date>
<is_new><![CDATA[0]]></is_new>
<car_type><![CDATA[hatchback]]></car_type>
<warranty><![CDATA[until 2011]]></warranty>
</ad>
</trovit>