我有来自 Ebay 的以下 XML 文件
<?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 的值,其中节点 Site 与我传递的任何变量匹配。我的代码是:
$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 的值。