【发布时间】:2016-09-22 07:03:33
【问题描述】:
例如,我的问题有很多答案 Parse XML namespaces with php SimpleXML 但我不明白在我的情况下如何调整代码以读取值?我有一个命名空间 m: 在命名空间肥皂内: 我需要解析这个 XML 并且只提取值 888-0000019749
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<m:SaveDocumentsResponse xmlns:m="http://www.cargo3.ru">
<m:return xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<m:Key>SaveDocuments</m:Key>
<m:List>
<m:Key>Order</m:Key>
<m:Properties>
<m:Key>Number</m:Key>
<m:Value xsi:type="xs:string">888-0000019749</m:Value>
<m:ValueType>string</m:ValueType>
</m:Properties>
<m:Properties>
<m:Key>CreateDate</m:Key>
<m:Value xsi:type="xs:dateTime">2016-05-23T20:56:50</m:Value>
<m:ValueType>dateTime</m:ValueType>
</m:Properties>
</m:List>
</m:return>
</m:SaveDocumentsResponse>
</soap:Body>
</soap:Envelope>
也无法处理这个例子 parse an XML with SimpleXML which has multiple namespaces 试过了
$xml = simplexml_load_string($res, NULL, NULL, "http://schemas.xmlsoap.org/soap/envelope/");
$xml->registerXPathNamespace('soap', 'http://schemas.xmlsoap.org/soap/envelope/');
$xml->registerXPathNamespace('m', 'http://www.w3.org/2001/XMLSchema');
foreach($xml->xpath('//m:SaveDocumentsResponse') as $header)
{
var_export($header->xpath('//m:return')); // Should output 'something'.
}
我又错过了什么……
一次又一次
echo $list = (string)$xml->children('soap', true)->Body->children('m', true)->SaveDocumentsResponse->return->List;
我需要最短、最简单的方法来从中提取价值
<m:Value xsi:type="xs:dateTime">2016-05-23T20:56:50</m:Value>
【问题讨论】:
-
您好,我对 SimpleXml 了解不多。我知道如何使用 DomDocument
-
嗨!任何方法都会给我带来一些经验。欢迎任何工作示例..
标签: php xml soap namespaces