从xml获取值标签

时间:2018-12-10 14:29:05

标签: php arrays xml string parsing

例如,如何从此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吗?谢谢!

2 个答案:

答案 0 :(得分:1)

您可以使用xpath来做到这一点。

df['mag'] = np.where(~df[['U', 'V', 'R', 'I']].eq(-999).any(1), (df.U - df.V) / (df.R - df.I), -999)

答案 1 :(得分:0)

$crawler = new Crawler($xml); // composer require symfony/dom-crawler
$first = $crawler->filter('Customer')->filter('Code')->text();
$second = $crawler->filter('ShipToAddress')->filter('Code')->text();