我在 this tutorial 的 DOM 解析器的代码中看到了以下行.
doc.getDocumentElement().normalize();
我们为什么要进行这种标准化?
我读了docs但我一个字都听不懂。
Puts all Text nodes in the full depth of the sub-tree underneath this Node
好的,那么谁能给我看看(最好有图片)这棵树长什么样子?
谁能解释一下为什么需要标准化?
如果我们不规范化会发生什么?
最佳答案
句子的其余部分是:
where only structure (e.g., elements, comments, processing instructions, CDATA sections, and entity references) separates Text nodes, i.e., there are neither adjacent Text nodes nor empty Text nodes.
这基本上意味着下面的 XML 元素
<foo>hello
wor
ld</foo>
在非规范化节点中可以这样表示:
Element foo
Text node: ""
Text node: "Hello "
Text node: "wor"
Text node: "ld"
当归一化时,节点将如下所示
Element foo
Text node: "Hello world"
属性也是如此:<foo bar="Hello world"/>
、评论等。
关于java - 使用 java 进行 DOM 解析的规范化 - 它是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13786607/