Category XML

XML DOM Create Nodes

Create a New Element Node The createElement() method creates a new element node: Example newElement = xmlDoc.createElement(“edition”); xmlDoc.getElementsByTagName(“book”)[0].appendChild(newElement);

XML DOM Replace Nodes

The replaceChild() method replaces a specified node. The nodeValue property replaces text in a text node. Replace an Element Node The replaceChild() method is used to replace a node. The following code fragment replaces the first <book> element:

XML DOM Remove Nodes

The removeChild() method removes a specified node. The removeAttribute() method removes a specified attribute. Remove an Element Node The removeChild() method removes a specified node. When a node is removed, all its child nodes are also removed.

XML DOM Change Node Values

The nodeValue property is used to change a node value. The setAttribute() method is used to change an attribute value. Change the Value of an Element In the DOM, everything is a node. Element nodes do not have a text…

XML DOM Get Node Values

The nodeValue property is used to get the text value of a node. The getAttribute() method returns the value of an attribute. Get the Value of an Element In the DOM, everything is a node. Element nodes do not have…

XML DOM – Navigating Nodes

Nodes can be navigated using node relationships. Navigating DOM Nodes Accessing nodes in the node tree via the relationship between nodes, is often called “navigating nodes”. In the XML DOM, node relationships are defined as properties to the nodes: parentNode…

XML DOM Traverse Node Tree

Traversing means looping through or traveling across the node tree. Traversing the Node Tree Often you want to loop an XML document, for example: when you want to extract the value of each element. This is called “Traversing the node…

XML DOM Node List

A list of nodes is returned by the getElementsByTagName() method and the childNodes property. DOM Node List When using properties or methods like childNodes or getElementsByTagName(), a node list object is returned. A node list object represents a list of…