topical media & game development

talk show tell print

basic-xml-11-ChildNodes.htm / htm



  <html>
   <head>
    <title>Retrieve information about child nodes.</title>
   </head>
   <body>
    <script language="JScript" type="text/javascript">
     try {
     var strXML = "<?xml version='1.0' ?><Book><Chapter>This is Chapter 1.</Chapter><Chapter>This is Chapter 2.</Chapter><Chapter>This is Chapter 3.</Chapter></Book>"
     var objXMLDOM = new ActiveXObject("Msxml2.DOMDocument.3.0");
     objXMLDOM.loadXML(strXML);
  
     var strDisplay;
     strDisplay = "";
     strDisplay += "The name of the first child node is: "
      + objXMLDOM.documentElement.firstChild.nodeName + "\n";
     strDisplay += "Its text content is: " 
     + objXMLDOM.documentElement.firstChild.firstChild.nodeValue + "\n";
     strDisplay += "The name of the last child node is: " 
     + objXMLDOM.documentElement.lastChild.nodeName + "\n";
     strDisplay += "Its text content is: " 
     + objXMLDOM.documentElement.lastChild.firstChild.nodeValue + "\n";
     alert(strDisplay);
  
    }
  
    catch (e)
     {
      alert("An exception has occurred.");
     }
   </script>
   </body>
  </html>


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.