我想解析一个特定的XML提要,但我使用SIMPLEXML
获得空值任何帮助都将非常感激。
这是Trovit XML Feed的一个例子。
例如,我使用下面的文件:
$ 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>