# XML DOM Node Types

« Previous
Next Chapter »

The DOM presents a document as a hierarchy of node objects.

## Try it Yourself - Examples

The examples below use the XML file books.xml.
A function, loadXMLDoc(), in an external JavaScript is used to load the XML file.

Display nodeName and nodeType of all elements

Display nodeName and nodeValue of all elements

## Node Types

The following table lists the different W3C node types, and which node types they may have as children:

Node Type | Description | Children
--- | --- | ---
Document | Represents the entire document (the root-node of the DOM tree) | Element (max. one), ProcessingInstruction, Comment, DocumentType
DocumentFragment | Represents a "lightweight" Document object, which can hold a portion of a document | Element, ProcessingInstruction, Comment, Text, CDATASection, EntityReference
DocumentType | Provides an interface to the entities defined for the document | None
ProcessingInstruction | Represents a processing instruction | None
EntityReference | Represents an entity reference | Element, ProcessingInstruction, Comment, Text, CDATASection, EntityReference
Element | Represents an element | Element, Text, Comment, ProcessingInstruction, CDATASection, EntityReference
Attr | Represents an attribute | Text, EntityReference
Text | Represents textual content in an element or attribute | None
CDATASection | Represents a CDATA section in a document (text that will NOT be parsed by a parser) | None
Comment | Represents a comment | None
Entity | Represents an entity | Element, ProcessingInstruction, Comment, Text, CDATASection, EntityReference
Notation | Represents a notation declared in the DTD | None

## Node Types - Return Values

The following table lists what the nodeName and the nodeValue properties will return for each node type:

Node Type | nodeName returns | nodeValue returns
--- | --- | ---
Document | #document | null
DocumentFragment | #document fragment | null
DocumentType | doctype name | null
EntityReference | entity reference name | null
Element | element name | null
Attr | attribute name | attribute value
ProcessingInstruction | target | content of node
Comment | #comment | comment text
Text | #text | content of node
CDATASection | #cdata-section | content of node
Entity | entity name | null
Notation | notation name | null

## NodeTypes - Named Constants

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

« Previous
Next Chapter »

### WEB HOSTING

UK Reseller Hosting

### WEB BUILDING

FREE Website BUILDER Free HTML5 Templates

### W3SCHOOLS EXAMS

HTML, CSS, JavaScript, PHP, jQuery, XML, and ASP Certifications

### SHARE THIS PAGE

### Color Picker

### HTML/CSS

HTML Tutorial HTML5 Tutorial CSS Tutorial CSS3 Tutorial Bootstrap Tutorial

### JavaScript

JavaScript Tutorial jQuery Tutorial jQuery Mobile Tutorial AngularJS Tutorial AJAX Tutorial JSON Tutorial

### Graphics

Canvas Tutorial SVG Tutorial Google Maps Tutorial

### Server Side

SQL Tutorial PHP Tutorial ASP Tutorial ASP.NET Tutorial VBScript Tutorial AppML Tutorial

### Web

Web Building Web Statistics Web Certification

### XML

XML Tutorial DTD Tutorial Schema Tutorial XML DOM Tutorial XPath Tutorial XSLT Tutorial XQuery Tutorial XSL-FO Tutorial RSS Tutorial WSDL Tutorial

### HTML/CSS

HTML Tag Reference HTML Event Reference HTML Color Reference CSS 1,2,3 Reference Bootstrap Reference

### JavaScript

JavaScript Reference HTML DOM Reference jQuery Reference jQuery Mobile Reference Google Maps Reference

### Server Side

PHP Reference SQL Reference ASP Reference VBScript Reference Razor Reference ASP.NET Reference

### XML

XML DOM Reference XSLT Reference XSL-FO Reference XPath Reference XQuery Reference Schema Reference RSS Reference SVG Reference

### HTML Charsets

HTML Character Sets HTML ASCII HTML ANSI HTML Windows-1252 HTML ISO-8859-1 HTML Symbols HTML UTF-8

### HTML/CSS

HTML Examples CSS Examples

### Browser Scripting

JavaScript Examples HTML DOM Examples jQuery Examples jQuery Mobile Examples AngularJS Examples AJAX Examples

### Server Scripting

PHP Examples ASP Examples VBScript Examples Razor Examples .NET Examples

### XML Languages

XML Examples DTD Examples XML DOM Examples XSL Examples XSLT Examples XPath Examples XQuery Examples Schema Examples RSS Examples SVG Examples