为什么XML中的节点和元素不同?什么是理由? [英] Why are Nodes and Elements different in XML? What was the rationale?
问题描述
有什么特殊的语义或实际的原因,还是仅仅是事实上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 elementa="myAttribute"
is an attributeSomeText
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屋!