xml中element和node的区别

 

The Node object is the primary data type for the entire DOM.

A node can be an element node, an attribute node, a text node, or any other of the node types explained in the “Node types” chapter.

An XML element is everything from (including) the element’s start tag to (including) the element’s end tag.

From: http://stackoverflow.com/questions/132564/whats-the-difference-between-an-element-and-a-node-in-xml

Element:
It is the main tag that can contain the data.
Node:
It is like a super type of an element

example:

<?xml version="1.0"?> 
<catalog> 
    <book bookid="b001"> 
        <bookname>ASP.NET</bookname> 
    </book> 
</catalog>
  

In this example:

Elements:

<catalog></catalog> 
<book></book> 
<bookname>ASP.NET</bookname> 

Nodes:

all are nodes

<?xml version="1.0"?> 
<catalog>: elements are also nodes. 
<book bookid="b001"> 
<bookname>ASP.NET</bookname> 
</book> 
</catalog> 

1)Processing Instruction:

<?xml version="1.0"?> 

It is a node

2)all elements are nodes:

3) The attribute bookid is also a node.

4)data in the element (i.e. ASP.NET is also a Node)
XML DOM Node Types

NodeType Named Constant
1 ELEMENT_NODE
2 ATTRIBUTE_NODE
3 TEXT_NODE
4 CDATA_SECTION_NODE
5 ENTITY_REFERENCE_NODE
6 ENTITY_NODE
7 PROCESSING_INSTRUCTION_NODE
8 COMMENT_NODE
9 DOCUMENT_NODE
10 DOCUMENT_TYPE_NODE
11 DOCUMENT_FRAGMENT_NODE
12 NOTATION_NODE

Refer to http://www.dotnetfunda.com/interview/exam3963-difference-between-an-element-and-node-in-xml.aspx

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值