[英]Obtain value tag from xml
How can i get the value of tag first "Code" for example from this 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>
I must use the function SimpleXML? 我必须使用功能SimpleXML吗? Thanks! 谢谢!
you can use xpath to do this. 您可以使用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.