How to use DOM Traverse Node Tree in XML

In this article I am going to explain about DOM Traverse Node Tree in XML.
  • 2018

XML DOM Travers Node Tree

Traversing Node tree is the process by which we can extract the value of each element. In other word we can say that traversing is the process by which we can traveling across the node tree in my XML document.

Example

Following example will display name and value of child node of "Details" element.

<html>

<head>

    <script type="text/javascript" src="myfile.js"></script>

</head>

<body>

    <script type="text/javascript">

        str = "<Detail>";

        str = str + "<Name>Ajay</Name>";

        str = str + "<Addredss>New Delhi</Address>";

        str = str + "<phone>863832224</phone>";

        str = str + "</Detail>";

 

        xmlDoc = loadXMLString(str);

 

        ss = xmlDoc.documentElement.childNodes;

        for (i = 0; i < ss.length; i++) {

            document.write(ss[i].nodeName);

            document.write(": ");

            document.write(ss[i].childNodes[0].nodeValue);

            document.write("<br />");

        }

    </script>

</body>

</html>

 

You may also want to read these related articles: here
Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

 

 

© 2019 DotNetHeaven. All rights reserved.