Difference between an Element and Node in XML .

 Posted by Ddd on 2/13/2011 | Category: Web Services, Remoting Interview questions | Views: 11266 | Points: 40
Answer:

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.w3schools.com


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response