致尊敬的讀者從simpleXML數組中獲取數據
我試圖從pubmed中獲取的xml數據數組中檢索數據。該陣列是這樣的:
<summa>
<DocS>
<Id>1</Id>
<Item Name="PubDate" Type="Date">1999</Item>
<Item Name="EPubDate" Type="Date"/> //<- notice the open tag
<Item Name="Source" Type="String">source a</Item>
<Item Name="AuthorList" Type="List">
<Item Name="Author" Type="String">a</Item>
<Item Name="Author" Type="String">b</Item>
</Item>
</DocS>
<DocS>
<Id>2</Id>
<Item Name="PubDate" Type="Date">1781</Item>
<Item Name="EPubDate" Type="Date"/></Item> //<- notice the closed tag
<Item Name="Source" Type="String">source a</Item>
<Item Name="AuthorList" Type="List">
<Item Name="Author" Type="String">a</Item>
<Item Name="Author" Type="String">b</Item>
<Item Name="Author" Type="String">c</Item>
<Item Name="Author" Type="String">d</Item>
</Item>
</DocS>
</summa>
數組是可變長,但總會有初始結構是這樣的:
<summa>
<DocS>
<Id>1</Id>
<Item Name="PubDate" Type="Date">1999</Item>
的數據,我特別需要的是這個
<Item Name="PubDate" Type="Date">data needed </Item>"
下面的代碼是我正在嘗試,它不起作用。有誰能夠幫助我?
$pmid_all=file_get_contents($url_id);
$p=simplexml_load_string($pmid_all);
$result = $p->xpath('/item');
while(list(, $node) = each($result)) {
echo 'item: ',$node,"\n";
}
「不起作用」,如:xpath查詢中的「no results」?一個錯誤?請儘量更精確。 – ccKep
xml無效 –