以文本方式查看主题 - ╋艺 镇╋ (http://wdystv.com/bbs/index.asp) -- ┣◇网站建设&Web语言 (http://wdystv.com/bbs/list.asp?boardid=4) ---- xml中Node和Element的区别 (http://wdystv.com/bbs/dispbbs.asp?boardid=4&id=2335) |
-- 作者:乐魔舞 -- 发布时间:2010/10/9 10:23:42 -- xml中Node和Element的区别 NODE是相对TREE这种数据结构而言的。TREE就是由NODE组成。这个部分你可以参考离散数学的树图。 什么是element ELEMENT则是XML里的概念,<xxx>就是元素,是XML中的数据的组成部分之一。 元素(Element)和结点(Node)的区别,元素是一个小范围的定义,必须是含有完整信息的结点才是一个元素,例如<div>...</div>。但是一个结点不一定是一个元素,而一个元素一定是一个结点。 <a> <b> </b> <b> </b> <a> DOM将文档中的所有都看作节点 node>element 1DOM在解析文档的时候按整个文档的结构生成一棵树,全部保存在内存 优点就是整个文档都一直在内存中,我们可以随时访问任何节点,并且对树的遍历也是比较熟悉的操作;缺点则是耗内存,并且必须等到所有的文档都读入内存才能进行处理。 Element root = doc.getDocumentElement();:root是什么???? NodeList list = root.getChildNodes(); root 到底是节点还是元素我不清楚?????
Element, Text, Attribute, RootElement, Comment, Namespace等 Element是从Node继承的 http://blog.csdn.net/wcydiyi/archive/2009/08/12/4432636.aspx [此贴子已经被作者于2010-10-9 10:24:01编辑过]
|
-- 作者:admin -- 发布时间: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等。 |