2012-03-22 103 views
-1

我無法解析xml文檔。 以及我的任務就是那樣無法解析xml數據

我從包含IP信息

<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> 

捲曲了XML頁面我嘗試分析它

$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試圖獲取非對象的屬性在行#

回答

3

您的XML無效。它在數據末尾有一個根元素結束標記

</ipinfo> 

但是沒有標題標記。如果您的策略:

<ipinfo> 

到它的面前我打賭它會工作。

+0

謝謝.....我們有時會忘記一些小事情,它們會造成麻煩:D – user114500 2012-03-23 01:27:42