2010-03-30 98 views
0
<Placemark id="p1"></Placemark> 
<Placemark id="p2"></Placemark> 
<Placemark id="p3"></Placemark> 
<Placemark id="p4"></Placemark> 

嗨,我在PHP中使用的SimpleXMLElement IM, 我的問題是,我如何得到標編號3? 是這樣的嗎?PHP的XML的SimpleXMLElement

$page = utf8_encode(file_get_contents($request_url)); 
$xml = new SimpleXMLElement($page); 
$xml->Response->Placemark['id=p3']->AddressDetails->Country->CountryName; 

感謝

+1

你有ID = 3在你的PHP代碼,但ID = 「P3」 在你的XML。我不知道這是否會造成您的問題。 – easement 2010-03-30 14:14:27

回答

1
$xml->xpath("Placemark[@id='p3']")->AddressDetails->Country->CountryName; 

XPath是你的朋友:-)