[英]Obtain value tag from xml
例如,如何從此XML獲取標記“代碼”開頭的值?
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<wsm:CreateCustomer>
<wsm:xmlCustomer>
<x60:Customer>
<x60:Code></x60:Code>
<x60:Shippment>
<x60:ShipToAddress>
<x60:Code></x60:Code>
<x60:ShipISOCountry></x60:ShipISOCountry>
</x60:ShipToAddress>
</x60:Shippment>
</x60:Customer>
</wsm:xmlCustomer>
</wsm:CreateCustomer>
</soapenv:Body>
</soapenv:Envelope>
我必須使用功能SimpleXML嗎? 謝謝!
您可以使用xpath來做到這一點。
$xml = new SimpleXMLElement($string);
$result = $xml->xpath('//*/x60:Code');
while(list( , $node) = each($result)) {
echo 'Code = ',$node,"\n";
break;
}
$crawler = new Crawler($xml); // composer require symfony/dom-crawler
$first = $crawler->filter('Customer')->filter('Code')->text();
$second = $crawler->filter('ShipToAddress')->filter('Code')->text();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.