我正在尝试获取值或所有 a: 属性
I am trying to get the values or all the a: attributes
我用过PHPSimpleXML、simplexml_load_string,用了DOM和SimpleXML[=13=也没有反应]
//Php XML 回应
$xml = <<<XML
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<StatusResponse xmlns="http://tempuri.org/">
<Result xmlns:a="http://schemas.datacontract.org/2004/07/OS.FLC" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:ResCode>OK</a:ResCode>
<a:IDNumber>149897</a:IDNumber>
<a:CusName>AXIOS ASOS</a:CusName>
<a:HoldName>AXA AXIOS</a:HoldName>
</Result>
</StatusResponse>
</s:Body>
</s:Envelope>
XML;
// 使用 PHP 简单 XML
$domContent = new SimpleXMLElement(((string)$xml), LIBXML_COMPACT);
$test = $domContent->xpath('/Result/a/*');
foreach ($test as $node)
{
print_r($node);
}
//使用DOM
$domp = new DOMDocument('1.0', 'utf-8');
$domp->loadXML($xml);
$items = $domp->getElementsByTagName('a');
foreach ($items as $item)
{
$HOLDER = $item->getElementsByTagNameNS("http://schemas.datacontract.org/2004/07/OS.FLC", "*")->Result(0)->nodeValue;
echo "HoldName = " . $HOLDER . PHP_EOL;
}
// Expected Result
ResCode = OK
IDNumber = 149897
CusName = AXIOS ASOS
使用 DOMDocument,您可以使用 getElementsByTagNameNS
并指定 a
的整个 URL :
$doc = new DOMDocument('1.0', 'utf-8');
$doc->loadXML($xml);
$elements = $doc->getElementsByTagNameNS('http://schemas.datacontract.org/2004/07/OS.FLC', '*');
foreach($elements as $elem)
{
echo $elem->nodeName . ' -> ' . $elem->nodeValue ;
}
输出:
a:ResCode -> OK
a:IDNumber -> 149897
a:CusName -> AXIOS ASOS
a:HoldName -> AXA AXIOS
我用过PHPSimpleXML、simplexml_load_string,用了DOM和SimpleXML[=13=也没有反应]
//Php XML 回应
$xml = <<<XML
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<StatusResponse xmlns="http://tempuri.org/">
<Result xmlns:a="http://schemas.datacontract.org/2004/07/OS.FLC" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:ResCode>OK</a:ResCode>
<a:IDNumber>149897</a:IDNumber>
<a:CusName>AXIOS ASOS</a:CusName>
<a:HoldName>AXA AXIOS</a:HoldName>
</Result>
</StatusResponse>
</s:Body>
</s:Envelope>
XML;
// 使用 PHP 简单 XML
$domContent = new SimpleXMLElement(((string)$xml), LIBXML_COMPACT);
$test = $domContent->xpath('/Result/a/*');
foreach ($test as $node)
{
print_r($node);
}
//使用DOM
$domp = new DOMDocument('1.0', 'utf-8');
$domp->loadXML($xml);
$items = $domp->getElementsByTagName('a');
foreach ($items as $item)
{
$HOLDER = $item->getElementsByTagNameNS("http://schemas.datacontract.org/2004/07/OS.FLC", "*")->Result(0)->nodeValue;
echo "HoldName = " . $HOLDER . PHP_EOL;
}
// Expected Result
ResCode = OK
IDNumber = 149897
CusName = AXIOS ASOS
使用 DOMDocument,您可以使用 getElementsByTagNameNS
并指定 a
的整个 URL :
$doc = new DOMDocument('1.0', 'utf-8');
$doc->loadXML($xml);
$elements = $doc->getElementsByTagNameNS('http://schemas.datacontract.org/2004/07/OS.FLC', '*');
foreach($elements as $elem)
{
echo $elem->nodeName . ' -> ' . $elem->nodeValue ;
}
输出:
a:ResCode -> OK
a:IDNumber -> 149897
a:CusName -> AXIOS ASOS
a:HoldName -> AXA AXIOS