I'm working in Java with XML and I'm wondering; what's the difference between an element and a node?
So, in a nutshell, a node is any DOM object. An element is one specific type of node as there are many other types of nodes (text nodes, comment nodes, document nodes, etc...). The DOM consists of a hierarchy of nodes where each node can have a parent, a list of child nodes and a nextSibling and previousSibling.
Everything in an XML document is a node. For example, the entire document is the document node, and every element is an element node. Root node. The topmost node of a tree. In the case of XML documents, it is always the document node, and not the top-most element.
An XML element is everything from (including) the element's start tag to (including) the element's end tag. <price>29.99</price> An element can contain: text. attributes.
According to the XML DOM, everything in an XML document is a node: The entire document is a document node. Every XML element is an element node. The text in the XML elements are text nodes. Every attribute is an attribute 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.
Different W3C specifications define different sets of "Node" types.
Thus, the DOM spec defines the following types of nodes:
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 The XML Infoset (used by XPath) has a smaller set of nodes:
XPath has the following Node types:
The answer to your question "What is the difference between an element and a node" is:
An element is a type of node. Many other types of nodes exist and serve different purposes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With