Php 从xml获取值标记

Php 从xml获取值标记,php,arrays,xml,string,parsing,Php,Arrays,Xml,String,Parsing,例如,如何从这个XML获取标记优先代码的值 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Header/> <soapenv:Body> <wsm:CreateCustomer> <wsm:xmlCustom

例如,如何从这个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; 
}

请向我们展示您尝试过但无法正常工作的内容。wsm和x60命名空间均未声明,因此XML本身无效。我错在哪里?未定义每个不推荐的DWSM命名空间,在第一条记录之后打破循环。
$crawler = new Crawler($xml); // composer require symfony/dom-crawler
$first = $crawler->filter('Customer')->filter('Code')->text();
$second = $crawler->filter('ShipToAddress')->filter('Code')->text();