Php DOMDocument-在不添加名称空间的情况下获取节点XML
测试XML:Php DOMDocument-在不添加名称空间的情况下获取节点XML,php,xml,domdocument,Php,Xml,Domdocument,测试XML: <?xml version="1.0" encoding="UTF-8" standalone="no" ?> <testroot xmlns:abc="http://abc"> <testA>testNodeText</testA> </testroot> 结果: // 1 <testroot xmlns:abc="
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<testroot xmlns:abc="http://abc">
<testA>testNodeText</testA>
</testroot>
结果:
// 1
<testroot xmlns:abc="http://abc">\n
<testA>testNodeText</testA>\n
</testroot>
// 2
<testA xmlns:abc="http://abc">testNodeText</testA>
//1
\n
testNodeText\n
// 2
testNodeText
获取节点的内容时,DOMDocument正在添加命名空间。问题是testA
节点不等于相同的testA
节点。当从XML的某些部分创建哈希值时,这会产生巨大的影响。
我无法从XML中获取节点并从中计算哈希,因为存在从文档根移动的名称空间
您知道如何从DOMDocument中获取节点内容以使其与原始文档中的内容保持一致吗?Does
$dom->saveXML($dom->getElementsByTagName('testA')->item(0))
以后做什么?您不能保证文档元素在解析后以相同的方式呈现。这两个节点是相等的,因为它们对XML解析器的意义相同。如果要计算某个内容的哈希,请对节点的内容而不是节点的XML表示进行计算。
// 1
<testroot xmlns:abc="http://abc">\n
<testA>testNodeText</testA>\n
</testroot>
// 2
<testA xmlns:abc="http://abc">testNodeText</testA>