HOME

XML DOM Tutorial
DOM HOME
DOM Introduction
DOM Parsing
DOM ParseError
DOM Validator
DOM Access
DOM HttpRequest
DOM NodeType

XML DOM Objects
DOM Node
DOM NodeList
DOM Document
DOM Element
DOM Attr
DOM Text
DOM CDATA
DOM Comment

Examples
DOM Examples
Download XMLSpy here
Please visit our sponsors !

DOM - The Node object

prev next
Take a look at the XML file used in the examples: note.xml

Examples

nodeName
How to return the name of a node.

nodeValue
How to return the value of a node.

nextSibling
How to return the name of the nextSibling node.

Text
In IE5 you can return the text from a node and all its child nodes.

xml
In IE5 you can return the xml from a node and all its child nodes.

appendChild
How to create an element node with a text node and then append it as a child node.

insertBefore
How to create a text node and then insert it before a specified node.


The Node Object

The node object represents a node in the node tree. A node can be an element node, a text node, or any other of the node types explained in the DOM nodeType chapter. All of these node types have properties and methods. The general properties and methods for all node types are listed below:

W3C Properties

Property Description
attributes Returns a NamedNodeMap containing all attributes for this node
childNodes Returns a NodeList containing all the child nodes for this node
firstChild Returns the first child node for this node
lastChild Returns the last child node for this node
nextSibling Returns the next sibling node. Two nodes are siblings if they have the same parent node
nodeName Returns the nodeName, depending on the type
nodeType Returns the nodeType as a number
nodeValue Returns, or sets, the value of this node, depending on the type
ownerDocument Returns the root node of the document
parentNode Returns the parent node for this node
previousSibling Returns the previous sibling node. Two nodes are siblings if they have the same parent node

W3C Methods

Method Description
appendChild(newChild) Appends the node newChild at the end of the child nodes for this node
cloneNode(boolean) Returns an exact clone of this node. If the boolean value is set to true, the cloned node contains all the child nodes as well
hasChildNodes() Returns true if this node has any child nodes
insertBefore(newNode,refNode) Inserts a new node, newNode, before the existing node, refNode
removeChild(nodeName) Removes the specified node, nodeName
replaceChild(newNode,oldNode) Replaces the oldNode, with the newNode


IE5 Node Properties and Methods

The node object has some properties and methods that are defined in Internet Explorer 5 only:

IE5 Properties

Property Description
basename Returns the nodeName without the namespaces
dataType Returns, or sets, the dataType for this node
definition  
nodeTypeString Returns the nodeType as a string
nodeTypedValue  
specified Returns whether the nodeValue is specified in the DTD/Schema or not
text Returns, or sets, the text for this node and all its child nodes
xml Returns, or sets, the xml for this node and all its child nodes

IE5 Methods

Method Description
selectNodes(pattern)  
selectSingleNode(pattern)  
transformNode(stylesheet) Processes the node and its childNodes with the specified XSL stylesheet, and returns the result


prev next

Jump to: Top of Page or HOME or Printer Friendly Printer friendly page


Search W3Schools:


What Others Say About Us

Does the world know about us? Check out these places:

Dogpile Alta Vista MSN Google Excite Lycos Yahoo Ask Jeeves


We Help You For Free. You Can Help Us!


W3Schools is for training only. We do not warrant its correctness or its fitness for use. The risk of using it remains entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.

Copyright 1999-2002 by Refsnes Data. All Rights Reserved


Validate How we converted to XHTML Validate

IISProtect
Password Protect
Your Web Pages



Your own Web Site?

Read W3Schools
Hosting Tutorial



$15 Domain Name
Registration
Save $20 / year!



Advertise
at W3Schools

Only 0.5 CPM



SELECTED LINKS

University Online
Master Degree
Bachelor Degree


Web Software

The Future of
Web Development


Jobs and Careers

Web Security
Web Statistics
Web Standards


PARTNERS

W3Schools
TopXML
VisualBuilder
XMLPitstop
DevelopersDex
DevGuru
Programmers Heaven
The Code Project
Tek Tips Forum
ZVON.ORG
TopXML Search