What are the difference between an element and a node in XML ?
What are the difference between an element and a node in XML ?
Here is the statement:
-
- The primary data type for the entire DOM is the Node object.
-
- Node should be an element node, a text node, an attribute node or any of the “Node types”.
-
- An XML element is all from including the element’s start tag to the element’s end tag.
DOM spec defines some types of nodes were:
- Document — Element (maximum of one), ProcessingInstruction, Comment, DocumentType
- DocumentFragment — Element, ProcessingInstruction, Comment, Text, CDATASection, EntityReference
- DocumentType — no children
- EntityReference — Element, ProcessingInstruction, Comment, Text, CDATASection, EntityReference
- Element — Element, Text, Comment, ProcessingInstruction, CDATASection, EntityReference
- Attr — Text, EntityReference
- ProcessingInstruction — no children
- Comment — no children
- Text — no children
- CDATASection — no children
- Entity — Element, ProcessingInstruction, Comment, Text, CDATASection, EntityReference
- Notation — no children
XML Infoset that used by XPath has a smaller set of nodes:
- The Document Information Item
- Element Information Items
- Attribute Information Items
- Processing Instruction Information Items
- Unexpanded Entity Reference Information Items
- Character Information Items
- Comment Information Items
- The Document Type Declaration Information Item
- Unparsed Entity Information Items
- Notation Information Items
- Namespace Information Items
XPath have some types of nodes:
- root nodes
- element nodes
- text nodes
- attribute nodes
- namespace nodes
- processing instruction nodes
- comment nodes
An element is a type of node. Many other types of nodes abide and serve different purposes.
Simple answer:
An element is an individual kind of node. A node can be a number of various type of things: some text, an element, an entity and a comment.