我有一个字符串,它从其他服务器动态获取其值。
字符串的值为
$string1 = '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.microsoft.com/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<AuthenticateUserResponse xmlns="http://microsoft.com/xml/namespace/2012/04">
<Authenticator>AE1001</Authenticator>
</AuthenticateUserResponse>
</soap:Body>
</soap:Envelope>';
我的问题是,通常我们使用 *$xml = simplexml_load_file("test1.xml");* 来加载 XML 文件,但在我的要求中,它是String,我如何读取这个字符串值并提取子节点及其值?例子:
<Authenticator> and its value "AE1001" ?
有没有办法将其放入数组中?这样我就可以很容易地打印出它的节点值吗?
还学习DOM文档 http://php.net/manual/en/class.domdocument.php and XPath http://php.net/manual/en/class.domxpath.php。真的值得花时间。
$doc = new DOMDocument;
$doc->loadXML($string1);
echo $doc->getElementsByTagName('Authenticator')->item(0)->nodeValue; // AE1001
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)