╋艺 镇╋╋网站网络|程序语言|Flash╋┣◇网站建设&Web语言 → xml中Node和Element的区别


  共有20834人关注过本帖树形打印复制链接

主题:xml中Node和Element的区别

帅哥哟,离线,有人找我吗?
乐魔舞
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 天之飞雪
等级:青蜂侠 帖子:1427 积分:11370 威望:0 精华:7 注册:2007/12/25 16:21:28
xml中Node和Element的区别  发帖心情 Post By:2010/10/9 10:23:42 [只看该作者]

 

NODE是相对TREE这种数据结构而言的。TREE就是由NODE组成。这个部分你可以参考离散数学的树图。

什么是element

ELEMENT则是XML里的概念,<xxx>就是元素,是XML中的数据的组成部分之一。

元素(Element)和结点(Node)的区别,元素是一个小范围的定义,必须是含有完整信息的结点才是一个元素,例如<div>...</div>。但是一个结点不一定是一个元素,而一个元素一定是一个结点。

<a>

  <b> </b>

  <b> </b>

<a>

DOM将文档中的所有都看作节点 node>element

1DOM在解析文档的时候按整个文档的结构生成一棵树,全部保存在内存

优点就是整个文档都一直在内存中,我们可以随时访问任何节点,并且对树的遍历也是比较熟悉的操作;缺点则是耗内存,并且必须等到所有的文档都读入内存才能进行处理。
2一个需要注意的地方就是,XML文档两个标签之间的空白也是这棵树的一个节点(Text节点)。 <a> <b></b> <a> a有三个节点

Element root = doc.getDocumentElement();:root是什么????

NodeList list = root.getChildNodes();             root 到底是节点还是元素我不清楚?????


node有几个子类型:

    Element,

      Text,

    Attribute,

  RootElement,

    Comment,

    Namespace等
Element是可以有属性和子节点的node。

Element是从Node继承的


http://blog.csdn.net/wcydiyi/archive/2009/08/12/4432636.aspx

[此贴子已经被作者于2010-10-9 10:24:01编辑过]


  
“艺镇”官方站:www.zyzsky.com QQ群:1221854  回到顶部
美女呀,离线,留言给我吧!
admin
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 司令 亲民勋章
等级:管理员 帖子:3027 积分:27515 威望:0 精华:7 注册:2003/12/30 16:34:32
  发帖心情 Post By:2011/9/9 11:20:59 [只看该作者]

XmlElement is a subclass of XmlNode (and so is XmlAttribute, XmlText, XmlDocument, etc.). There is no performance implication of using one over the other at all, since XmlNode is simply the base class for all types of nodes in a DOM Xml document instance.

It just so happens, that many of the APIs in the DOM return an XmlNode reference because they could return several kinds of nodes. For example, with SelectSingleNode(), your XPath expression could return an element, an attribute, an XmlText and what not; whether you handle it as an XmlNode or cast it to the right type is just a matter of how you write your code but won't affect performance at all.

XmlElements are a type of node. In fact, if you look at the members of XmlNode and XmlElement in the .NET Framework, you will see that  they are   very much alike, but XmlElement has more going on. It inherits XmlNode and then is further customized. This is because an element is more   specialized. A node is more general in scope. The document is a node, a processing instruction is a node, and so forth. Elements are   different. If you look at the XmlNodeType property of an element, you will see that it is Element, one of the many types of nodes you find. 

 

Element是Node的子集,XmlNode表示一个节点,包括XmlElement(元素)和XmlAttribute(属性)等。 如:

<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><Alarm lock="true">             //node  
      <Time>                       //node  
          StringValue              //node  
      </Time>                      //node  
</Alarm>                           //node 

  以上Alarm(元素节点),lock(属性节点),Time(元素节点),StringValue(文本节点)都是Node,但是只有 <Alarm>......</Alarm>和<Time>StringValue</Time>是Element  

----------------以下是我自己的理解--------------

xml element是继承于node,除了element之外,还有XmlAttribute、XmlText等。
通过某些方法可能可以得到某个值,可能是element、attribute、xmlText等,如果你不确定,则可以使用node来做返回值的类型。
node只是具有了一些通用的方法,而element则具有更具体的功能。


http://www.cnblogs.com/stg609/articles/1414364.html



  
“艺镇”官方站:www.zyzsky.com QQ群:1221854  回到顶部