我无法解析xml文档。 我的任务就像那样
我从curl获得了包含ip info
的xml页面<ip_address>209.59.194.20</ip_address><ip_type>Mapped</ip_type><Network><organization>thoughtconvergence.com</organization><carrier>whidbey internet services</carrier><asn>6295</asn><connection_type/><line_speed/><ip_routing_type>fixed</ip_routing_type><Domain><tld>com</tld><sld>trafficz</sld></Domain></Network><Location><continent>north america</continent><latitude>34.03708</latitude><longitude>-118.42789</longitude><CountryData><country>united states</country><country_code>us</country_code><country_cf>99</country_cf></CountryData><region>southwest</region><StateData><state>california</state><state_code>ca</state_code><state_cf>80</state_cf></StateData><dma>803</dma><msa>31100</msa><CityData><city>los angeles</city><postal_code>90064</postal_code><time_zone>-8</time_zone><area_code>323</area_code><city_cf>61</city_cf></CityData></Location></ipinfo>
我试着解析它
$book = simplexml_load_string($datax);
$ipadd = $book->ip_address;
$ipatype = $book->ip_type;
$ip_routing_type = $book->Network->ip_routing_type;
$state = $book->Location->StateData->state;
$country = $book->Location->CountryData->country;
$continent = $book->Location->continent;
$region = $book->Location->region;
现在我的错误很少 1)实体:第2行:解析器错误:文档末尾的额外内容 2试图在第#
行中获取非对象的属性答案 0 :(得分:3)
您的XML无效。它在数据末尾有一个根元素的结束标记
</ipinfo>
但没有标头标签。如果你坚持:
<ipinfo>
到它的前面我敢打赌它会起作用。