How can i get the value of tag first "Code" for example from this 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>
I must use the function SimpleXML? Thanks!
you can use xpath to do this.
$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();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.