獲得價值我有followng XML文件來自eBayPHP的XPath - 如何從結果
<?xml version="1.0"?>
<GeteBayDetailsResponse xmlns="urn:ebay:apis:eBLBaseComponents">
<Timestamp>2012-07-04T12:02:14.541Z</Timestamp>
<Ack>Success</Ack>
<Version>779</Version>
<Build>E779_INTL_BUNDLED_14986004_R1</Build>
<SiteDetails>
<Site>US</Site>
<SiteID>0</SiteID>
<DetailVersion>1</DetailVersion>
<UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime>
</SiteDetails>
<SiteDetails>
<Site>Canada</Site>
<SiteID>2</SiteID>
<DetailVersion>1</DetailVersion>
<UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime>
</SiteDetails>
<SiteDetails>
<Site>UK</Site>
<SiteID>3</SiteID>
<DetailVersion>1</DetailVersion>
<UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime>
</SiteDetails>
<SiteDetails>
<Site>Germany</Site>
<SiteID>77</SiteID>
<DetailVersion>1</DetailVersion>
<UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime>
</SiteDetails>
<SiteDetails>
<Site>Australia</Site>
<SiteID>15</SiteID>
<DetailVersion>1</DetailVersion>
<UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime>
</SiteDetails>
<SiteDetails>
<Site>France</Site>
<SiteID>71</SiteID>
<DetailVersion>1</DetailVersion>
<UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime>
</SiteDetails>
<SiteDetails>
<Site>eBayMotors</Site>
<SiteID>100</SiteID>
<DetailVersion>1</DetailVersion>
<UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime>
</SiteDetails>
<SiteDetails>
<Site>Italy</Site>
<SiteID>101</SiteID>
<DetailVersion>1</DetailVersion>
<UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime>
</SiteDetails>
<SiteDetails>
<Site>Netherlands</Site>
<SiteID>146</SiteID>
<DetailVersion>1</DetailVersion>
<UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime>
</SiteDetails>
<SiteDetails>
<Site>Spain</Site>
<SiteID>186</SiteID>
<DetailVersion>1</DetailVersion>
<UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime>
</SiteDetails>
<SiteDetails>
<Site>India</Site>
<SiteID>203</SiteID>
<DetailVersion>1</DetailVersion>
<UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime>
</SiteDetails>
<SiteDetails>
<Site>HongKong</Site>
<SiteID>201</SiteID>
<DetailVersion>1</DetailVersion>
<UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime>
</SiteDetails>
<SiteDetails>
<Site>Singapore</Site>
<SiteID>216</SiteID>
<DetailVersion>1</DetailVersion>
<UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime>
</SiteDetails>
<SiteDetails>
<Site>Malaysia</Site>
<SiteID>207</SiteID>
<DetailVersion>1</DetailVersion>
<UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime>
</SiteDetails>
<SiteDetails>
<Site>Philippines</Site>
<SiteID>211</SiteID>
<DetailVersion>1</DetailVersion>
<UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime>
</SiteDetails>
<SiteDetails>
<Site>CanadaFrench</Site>
<SiteID>210</SiteID>
<DetailVersion>1</DetailVersion>
<UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime>
</SiteDetails>
<SiteDetails>
<Site>Poland</Site>
<SiteID>212</SiteID>
<DetailVersion>1</DetailVersion>
<UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime>
</SiteDetails>
<SiteDetails>
<Site>Belgium_Dutch</Site>
<SiteID>123</SiteID>
<DetailVersion>1</DetailVersion>
<UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime>
</SiteDetails>
<SiteDetails>
<Site>Belgium_French</Site>
<SiteID>23</SiteID>
<DetailVersion>1</DetailVersion>
<UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime>
</SiteDetails>
<SiteDetails>
<Site>Austria</Site>
<SiteID>16</SiteID>
<DetailVersion>1</DetailVersion>
<UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime>
</SiteDetails>
<SiteDetails>
<Site>Switzerland</Site>
<SiteID>193</SiteID>
<DetailVersion>1</DetailVersion>
<UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime>
</SiteDetails>
<SiteDetails>
<Site>Ireland</Site>
<SiteID>205</SiteID>
<DetailVersion>1</DetailVersion>
<UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime>
</SiteDetails>
<UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime>
</GeteBayDetailsResponse>
我需要得到節點SITEID在該節點匹配網站我傳進去的變量的值。我的代碼是:
$xml_file ='SiteDetails.xml';
$xmlDoc = new DomDocument();
$xmlDoc->load($xml_file);
$xpath = new DOMXpath($xmlDoc);
$siteIDList = $xpath->query("/GeteBayDetailsResponse/SiteDetails[Site=$site]/SiteID");
var_dump($siteIDList);
echo $siteIDList->SiteID;
我得到以下結果:
object(DOMNodeList)#11 (0) {
}
誰能幫助?我想獲得的3
通常對於很長的XML字符串(或者代碼當然),最好在粘貼之前將它很好地嵌套起來,這樣每個人都可以閱讀':)' – halfer