我知道这可能是一个新手问题,但请幽默。读取标签中带有“soap:”的 xml 字符串时,simplexml_load_string() 不会读取 xml。
给定这个脚本:
#!/usr/bin/php
<?php
$s='
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header>
<context xmlns="urn:zimbra"/>
</soap:Header>
<soap:Body>
<AuthResponse xmlns="urn:zimbraAdmin">
<authToken>somevalue</authToken>
<lifetime>123124123</lifetime>
<a n="zimbraIsDomainAdminAccount">false</a>
</AuthResponse>
</soap:Body>
</soap:Envelope>';
print_r(simplexml_load_string($s));
echo "\n\n";
print_r(simplexml_load_string(str_ireplace("soap:", "", $s)));
?>
我得到这个输出:
jesse@jesse-debian:~/code/zmsoap$ ./xmltest.php
SimpleXMLElement Object
(
)
SimpleXMLElement Object
(
[Header] => SimpleXMLElement Object
(
[context] => SimpleXMLElement Object
(
)
)
[Body] => SimpleXMLElement Object
(
[AuthResponse] => SimpleXMLElement Object
(
[authToken] => somevalue
[lifetime] => 123124123
[a] => false
)
)
)
jesse@jesse-debian:~/code/zmsoap$
我只是好奇为什么会发生这种情况,以及是否有更合适的方法来解决问题而不是进行字符串替换。