Keywords: XML | DOM | Node Types
Abstract: This article provides a comprehensive examination of the distinction between elements and nodes in XML Document Object Model (DOM). By analyzing W3C DOM specifications, it clarifies the fundamental role of nodes as base data types and elements as specific node subtypes. The paper details 12 standard node types with their hierarchical relationships, compares node classifications in XML Infoset and XPath, and offers complete technical reference for Java XML developers.
The Concept of Nodes in DOM Model
In the XML Document Object Model (DOM), the Node object serves as the fundamental data type for the entire DOM architecture. According to W3C DOM Level 1 specification, nodes form the complete tree structure of an XML document, with each document component existing as a specific type of node.
Node Type Hierarchy
The DOM specification defines a rich hierarchy of node types, primarily including:
Document- May contain at most oneElement,ProcessingInstruction,Comment, andDocumentTypeDocumentFragment- May containElement,ProcessingInstruction,Comment,Text,CDATASection, andEntityReferenceElement- May containElement,Text,Comment,ProcessingInstruction,CDATASection, andEntityReferenceAttr- May containTextandEntityReference- Other types include
ProcessingInstruction,Comment,Text,CDATASection,Entity,Notation, etc.
Definition and Characteristics of XML Elements
An XML element is a specific subtype of node, encompassing everything from the element's start tag to its end tag. In Java DOM programming, element nodes possess unique properties and methods for handling tag names, attributes, and child elements.
Node Classifications Across Different Specifications
The XML Infoset specification defines a different set of information items, including document information items, element information items, attribute information items, and 8 other types. The XPath specification adopts a more concise node classification: root nodes, element nodes, text nodes, attribute nodes, namespace nodes, processing instruction nodes, and comment nodes.
Core Distinction Summary
An element is one specific type of node within the DOM hierarchy. While all elements are nodes, not all nodes are elements. Understanding this containment relationship is crucial for properly manipulating XML documents, particularly when using Java DOM APIs to select appropriate node type handling methods.