是否有一種簡單的方法可以使用SimpleXML xpath來解析標籤名稱中冒號的標籤?使用PHP中的SimpleXML xpath使用冒號分析標籤
例子:
<v12:ProcessShipmentResponse>SUCCESS</v12:ProcessShipmentResponse>
這裏是我用來分析那些沒有命名空間,但與命名空間的標記符標記的代碼。
$xml = simplexml_load_string($responseXMLL, NULL, NULL, 'http://schemas.xmlsoap.org/soap/envelope/');
foreach ($xml->xpath('soapenv:Body') as $body) {
$custInfoArr['status'] = (string) $body->v12:ProcessShipmentReply->v12:HighestSeverity;
$custInfoArr['trackingCode'] = (string) $body->v12:ProcessShipmentReply->v12:CompletedShipmentDetail->v12:CompletedPackageDetails->v12:TrackingIds->v12:TrackingNumber;
$custInfoArr['labelCode'] = (string) $body->v12:ProcessShipmentReply->v12:CompletedShipmentDetail->v12:CompletedPackageDetails->v12:Label->v12:Parts->v12:Image;
}
這隻與使用XPath有關,而不是SimpleXML(' - > node'和'['attribute']')提供的普通對象和數組式訪問。 – IMSoP 2013-03-28 19:11:18
@IMSoP:是一種替代工作解決方案,不知道爲什麼你低估了。 – DonCallisto 2013-03-29 07:53:27
是的,但你沒有真正解釋如何使用它,看起來這是如何解決OP的代碼,除了一行是*不*使用XPath,並且不需要。 – IMSoP 2013-03-29 11:44:01