用DOM解析DOM的规范化 - 它是如何工作的? [英] Normalization in DOM parsing with java - how does it work?

查看:92
本文介绍了用DOM解析DOM的规范化 - 它是如何工作的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在本教程

doc.getDocumentElement().normalize();

为什么要做这种规范化?

我读了 docs ,但我无法理解一个字。 / p>

Why do we do this normalization ?
I read the docs but I could not understand a word.


将此节点下的子树的全部深度中的所有文本节点放在

Puts all Text nodes in the full depth of the sub-tree underneath this Node

好的,那么有人可以给我看看(最好是一张照片)这棵树是什么样的吗?

Okay, then can someone show me (preferably with a picture) what this tree looks like ?

任何人都可以解释为什么要规范化需要吗?

如果我们不正常化,会发生什么?

Can anyone explain me why normalization is needed?
What happens if we don't normalize ?

推荐答案

其余的句子是:


其中只有结构(例如,元素,注释,处理指令,CDATA部分和实体引用)分离文本节点,即那里既不是相邻的文本节点也不是空文本节点。

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元素

This basically means that the following XML element

<foo>hello 
wor
ld</foo>

可以在非规范化节点中表示为:

could be represented like this in a denormalized node:

Element foo
    Text node: ""
    Text node: "Hello "
    Text node: "wor"
    Text node: "ld"

当正常化时,节点将看起来像这样

When normalized, the node will look like this

Element foo
    Text node: "Hello world"

同样的属性:< foo bar =Hello world/> ,评论等。

And the same goes for attributes: <foo bar="Hello world"/>, comments, etc.

这篇关于用DOM解析DOM的规范化 - 它是如何工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆