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

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

问题描述

我在 本教程.

doc.getDocumentElement().normalize();

我们为什么要进行这种规范化?
我阅读了文档,但我一个字都听不懂.

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

将所有 Text 节点放在此节点下子树的完整深度

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 部分和实体引用)分隔 Text 节点,即既没有相邻的 Text 节点也没有空的 Text 节点.

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"/>、评论等

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

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