How to use XML DOM Navigate Nodes

In this article I am going to explain about XML DOM Navigate Nodes
  • 1912

XML DOM Navigating Node

Navigating Node is the process by which we can access the node in the node three by the relationship between node. In XML DOM Node relationship have following properties.

  • parentsNodes
  • childNodes
  • firstChild
  • LasdChild
  • priviousSibling
  • nextSibling

Following example navigate the parents node of  "myfile.xmlk".

<html>

<head>

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

</script>

</head>

<body>

 

<script type="text/javascript">

    Doce = loadXMLDoc("personDetail.xml");

 

    str = Doce.getElementsByTagName("person")[0];

    document.write(str.parentNode.nodeName);

</script>

</body>

</html>

 

Following example will display first child node of "person" element.

 

<html>

<head>

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

</script>

<script type="text/javascript">

   

    function getfirstnode(p) {

     x = p.firstChild;

        while (x.nodeType != 1) {

         x = x.nextSibling;

        }

        return x;

    }

</script>

</head>

 

<body>

<script type="text/javascript">

 doce = loadXMLDoc("Detail.xml");

 

 str = getfirstnode(doce.getElementsByTagName("person")[0]);

    document.write(str.nodeName);

</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
 

 

© 2020 DotNetHeaven. All rights reserved.