XML DOM - Document object

|  | Search W3Schools : |

HOME | HTML | CSS | XML | JAVASCRIPT | ASP | PHP | SQL | MORE... |  | References | Examples | Forum | About

ADVERTISEMENTS XML Certification Download XML editor Custom Programming |  |

Table of contents

XML DOM Tutorial
DOM HOME
DOM Introduction
DOM Nodes
DOM Node Tree
DOM Parsing
DOM Load Function
DOM Methods
DOM Accessing
DOM Node Info
DOM Node List
DOM Traversing
DOM Browsers
DOM Navigating
Manipulate Nodes
DOM Get Values
DOM Change Nodes
DOM Remove Nodes
DOM Replace Nodes
DOM Create Nodes
DOM Add Nodes
DOM Clone Nodes
DOM HttpRequest
XML DOM Reference
DOM Node Types
DOM Node
DOM NodeList
DOM NamedNodeMap
DOM Document
DOM DocumentImpl
DOM DocumentType
DOM ProcessingInstr
DOM Element
DOM Attribute
DOM Text
DOM CDATA
DOM Comment
DOM HttpRequest
DOM ParseError Obj
DOM Parser Errors
DOM Summary
Examples
DOM Examples
DOM Validator

Selected Reading

Web Statistics
Web Glossary
Web Hosting
Web Quality
W3Schools Tutorials
W3Schools Forum
Helping W3Schools

# XML DOM - The Document Object

The Document object represents the entire XML document.

## The Document object

The Document object is the root of a document tree, and gives us the primary access to the document's data.

Since element nodes, text nodes, comments, processing instructions, etc. cannot exist outside the document, the Document object also contains methods to create these objects. The Node objects have a ownerDocument property which associates them with the Document where they were created.

IE: Internet Explorer, F: Firefox, O: Opera, W3C: World Wide Web Consortium (Internet Standard)

### Document Object Properties

Property | Description | IE | F | O | W3C
--- | --- | --- | --- | --- | ---
async | Specifies whether downloading of an XML file should be handled asynchronously or not | 5 | 1.5 | 9 | No
childNodes | Returns a NodeList of child nodes for the document | 5 | 1 | 9 | Yes
doctype | Returns the Document Type Declaration associated with the document | 6 | 1 | 9 | Yes
documentElement | Returns the root node of the document | 5 | 1 | 9 | Yes
documentURI | Sets or returns the location of the document | No | 1 | 9 | Yes
domConfig | Returns the configuration used when normalizeDocument() is invoked |  |  | No | Yes
firstChild | Returns the first child node of the document | 5 | 1 | 9 | Yes
implementation | Returns the DOMImplementation object that handles this document | No | 1 | 9 | Yes
inputEncoding | Returns the encoding used for the document (when parsing) | No | 1 | No | Yes
lastChild | Returns the last child node of the document | 5 | 1 | 9 | Yes
nodeName | Returns the name of a node (depending on its type) | 5 | 1 | 9 | Yes
nodeType | Returns the node type of a node | 5 | 1 | 9 | Yes
nodeValue | Sets or returns the value of a node (depending on its type) | 5 | 1 | 9 | Yes
strictErrorChecking | Sets or returns whether error-checking is enforced or not | No | 1 | No | Yes
text | Returns the text of a node and its descendants. IE-only property | 5 | No | No | No
xml | Returns the XML of a node and its descendants. IE-only property | 5 | No | No | No
xmlEncoding | Returns the XML encoding of the document | No | 1 | No | Yes
xmlStandalone | Sets or returns whether the document is standalone | No | 1 | No | Yes
xmlVersion | Sets or returns the XML version of the document | No | 1 | No | Yes

### Document Object Methods

Method | Description | IE | F | O | W3C
--- | --- | --- | --- | --- | ---
adoptNode(sourcenode) | Adopts a node from another document to this document, and returns the adopted node |  |  | No | Yes
createAttribute(name) | Creates an attribute node with the specified name, and returns the new Attr object | 6 | 1 | 9 | Yes
createAttributeNS(uri,name) | Creates an attribute node with the specified name and namespace, and returns the new Attr object |  |  | 9 | Yes
createCDATASection() | Creates a CDATA section node | 5 | 1 | 9 | Yes
createComment() | Creates a comment node | 6 | 1 | 9 | Yes
createDocumentFragment() | Creates an empty DocumentFragment object, and returns it | 5 | 1 | 9 | Yes
createElement() | Creates an element node | 5 | 1 | 9 | Yes
createElementNS() | Creates an element node with a specified namespace | No | 1 | 9 | Yes
createEntityReference(name) | Creates an EntityReference object, and returns it | 5 |  | No | Yes
createProcessingInstruction(target,data) | Creates a ProcessingInstruction object, and returns it | 5 |  | 9 | Yes
createTextNode() | Creates a text node | 5 | 1 | 9 | Yes
getElementById(id) | Returns the element that has an ID attribute with the given value. If no such element exists, it returns null | 5 | 1 | 9 | Yes
getElementsByTagName() | Returns a NodeList of all elements with a specified name | 5 | 1 | 9 | Yes
getElementsByTagNameNS() | Returns a NodeList of all elements with a specified name and namespace | No | 1 | 9 | Yes
importNode(nodetoimport,deep) | Imports a node from another document to this document. This method creates a new copy of the source node. If the deep parameter is set to true, it imports all children of the specified node. If set to false, it imports only the node itself. This method returns the imported node |  |  | 9 | Yes
normalizeDocument() |  |  |  | No | Yes
renameNode() | Renames an element or attribute node |  |  | No | Yes

## Altova® MissionKit® - Integrated suite of XML tools

The Altova MissionKit is a suite of intelligent XML tools, including:

XMLSpy® – industry-leading XML editor

- Support for all XML-based technologies
- Graphical editing views, powerful debuggers, code generation, & more

MapForce® – graphical data mapping tool

- Drag-and-drop data conversion with code generation
- Support for XML, DBs, EDI, Excel® 2007, text, Web services

StyleVision® – visual stylesheet designer

- Drag-and-drop stylesheet design for XML & databases
- Output to HTML, PDF, RTF, Word 2007, & more

And more…

Try before you buy with a free fully functional 30-day trial

Download today

## Get Your Diploma!

W3Schools' Online Certification Program is the perfect solution for busy professionals who need to balance work, family, and career building.

The HTML Certificate is for developers who want to document their knowledge of HTML, XHTML, and CSS.

The JavaScript Certificate is for developers who want to document their knowledge of JavaScript and the HTML DOM.

The XML Certificate is for developers who want to document their knowledge of XML, XML DOM and XSLT.

The ASP Certificate is for developers who want to document their knowledge of ASP, SQL, and ADO.

The PHP Certificate is for developers who want to document their knowledge of PHP and SQL (MySQL).

WEB HOSTING
ASP.NET Web Hosting
$15 Domain Name Registration Save $20 / year!
Buy UK Domain Names Register Domain Names
Cheap Domain Names Cheap Web Hosting
Best Web Hosting
PHP MySQL Hosting
Top 10 Web Hosting
UK Reseller Hosting
Web Hosting
FREE Web Hosting

WEB BUILDING
Website Templates Flash Templates Website Builder Internet Business Opportunity
Custom Programming
FREE Trial or Demo Web Content Manager Forms,Web Alerts,RSS
Download XML editor
FREE Flash Website
FREE Web Templates

EDUCATION
US Web Design Schools
HTML Certification
JavaScript Certification
XML Certification
PHP Certification
ASP Certification

HOME or Top of Page |  | Printer Friendly
W3Schools is for training only. We do not warrant the correctness of its content. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy. Copyright 1999-2009 by Refsnes Data. All Rights Reserved.