我想在沒有遵循整個路徑的情況下找到xml響應中的一部分。現在我知道了XPath具有搜索能力,但不知何故,我不明白它... :(simplexml和使用相對路徑
我解析XML是這樣的:
<?xml version="1.0" encoding="utf-8"?>
<soapEnvelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<envHeader xmlns:env="http://www.w3.org/2003/05/soap-envelope">
<wsaAction>http://www.rechtspraak.nl/namespaces/cir01/searchUndertakingResponse</wsaAction>
<wsaMessageID>urn:uuid:11f7d4cd-2280-4298-85eb-dadf5bd743f1</wsaMessageID>
<wsaRelatesTo>urn:uuid:59630fbd-b990-4020-9c1c-822c58186d96</wsaRelatesTo>
<wsaTo>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsaTo>
<wsseSecurity>
<wsuTimestamp wsu:Id="Timestamp-df25f141-fed2-47ed-967e-93cd04d1c8f2">
<wsuCreated>2011-04-02T06:52:52Z</wsuCreated>
<wsuExpires>2011-04-02T06:57:52Z</wsuExpires>
</wsuTimestamp>
</wsseSecurity>
</envHeader>
<soapBody>
<searchUndertakingResponse xmlns="http://www.rechtspraak.nl/namespaces/cir01"><searchUndertakingResult>
<publicatieLijst xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" extractiedatum="2011-04-02T08:52:51" xmlns="http://www.rechtspraak.nl/namespaces/inspubber01">
<publicatieKenmerk>sgr.10.787.F.1300.1.10</publicatieKenmerk>
<publicatieKenmerk>utr.10.585.F.1300.1.10</publicatieKenmerk>
</publicatieLijst>
</searchUndertakingResult>
</searchUndertakingResponse>
</soapBody>
</soapEnvelope>
我期待這些值:<publicatieKenmerk>sgr.10.787.F.1300.1.10</publicatieKenmerk> <publicatieKenmerk>utr.10.585.F.1300.1.10</publicatieKenmerk>
現在這個工程:
$lijst = $results->soapBody->searchUndertakingResponse->searchUndertakingResult->publicatieLijst->publicatieKenmerk;
foreach ($lijst AS $kenmerk) {
echo $kenmerk."<BR>";
}
但是我不想用這個,因爲我需要靈活的其他結果,不能依靠 searchUn。 dertakingResponse-> searchUndertakingResult
,所以我希望使用XPath到那裏,但是這並不工作:
$lijst = $results->xpath('//publicatieKenmerk');
foreach($lijst as $kenmerk) {
echo $kenmerk."<br />";
}
但我認爲相對會工作,以及...任何想法?
我認爲這是對的preg_match和正則表達式或XML解析器的工作,但我不擅長這個。希望其他人會發布一段代碼。 – Wh1T3h4Ck5 2011-04-02 07:11:47