topical media & game development

talk show tell print

basic-xml-11-ChildNodes.htm / htm

    <title>Retrieve information about child nodes.</title>
    <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");
     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";
    catch (e)
      alert("An exception has occurred.");

(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.