Java Node normalize方法有什么作用? [英] What does Java Node normalize method do?

查看:132
本文介绍了Java Node normalize方法有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一些测试,但是当我使用或不使用normalize()方法时,我认为没有区别。
但是ExampleDepot网站上的示例使用它。
那么,它的用途是什么? (文档对我来说也不清楚)

I'm doing some tests, but I see no difference when I use or not the normalize() method. But the examples at ExampleDepot website use it. So, what is it for? (The documentation wasn't clear for me either)

推荐答案

您可以以编程方式构建一个具有无关结构的DOM树实际的XML结构 - 特别是像文本类型的多个节点彼此相邻,或类型为text的空节点。 normalize()方法删除了这些,即它组合了相邻的文本节点并删除了空文本节点。

You can programmatically build a DOM tree that has extraneous structure not corresponding to actual XML structures - specifically things like multiple nodes of type text next to each other, or empty nodes of type text. The normalize() method removes these, i.e. it combines adjacent text nodes and removes empty ones.

这可以是当你有其他代码希望DOM树看起来像是从实际的XML文档构建的东西时很有用。

This can be useful when you have other code that expects DOM trees to always look like something built from an actual XML document.

这基本上意味着以下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"

这篇关于Java Node normalize方法有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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