为什么XML中的节点和元素不同?什么是理由? [英] Why are Nodes and Elements different in XML? What was the rationale?

查看:85
本文介绍了为什么XML中的节点和元素不同?什么是理由?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一直在编写使用XML的代码一段时间,我一直想知道有两个节点和元素的原因是什么? (我们知道什么区别是)。两者都代表标签(或多或少),并且具有不同的方法,只是使代码变得复杂。



有什么特殊的语义或实际的原因,还是仅仅是事实上DOM规范是委员会生成的?

解决方案

Node是Element的基类 - 几乎所有的Xml文档都是一个节点,例如:

 <!ENTITY ...> 
< xml a =myAttribute>
SomeText
<! - 评论 - >
< / xml>

在上面的例子中:




  • <!ENTITY ...> 是一个实体

  • xml ... 是一个元素

  • a =myAttribute是一个属性

  • SomeText 是一个文本节点

  • <! - - > 是一个评论



所有上述都继承自Node,实际上在上面的例子中 myAttribute 也是一个文本节点。


Having been writing code that operates on XML for a while, I have always wondered what is the reason for having both Nodes and Elements? (We know what the differences are). Both of them represent tags (more or less) and having different methods, just makes the code complicated.

Are there any special semantics or practical reasons, or is it just the fact that the DOM spec was committee generated?

解决方案

Node is a base class of Element - pretty much everything in an Xml document is a Node, for example:

<!ENTITY...>
<xml a="myAttribute">
    SomeText
    <!-- A comment -->
</xml>

In the above example:

  • <!ENTITY...> is an entity
  • <xml ... is an element
  • a="myAttribute" is an attribute
  • SomeText is a text node
  • <!-- A comment --> is a comment

All of the above inherit from Node, in fact in the above example myAttribute is also a text node.

这篇关于为什么XML中的节点和元素不同?什么是理由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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