BuiltWithNOF
Example DOM

<html>
<body>

<script type="text/javascript">
var xmlDocument=new ActiveXObject("Microsoft.XMLDOM")
xmlDocument.async="false"
xmlDocument.load("classxml.xml")

     // get the root element
     var element = xmlDocument.documentElement;
  
     document.writeln( "<p>Here is the root node of the document: " + element.nodeName );

   </script>

   </body>
</html>

see it run:

 

<html>
<body>

<script type="text/javascript">
var xmlDocument=new ActiveXObject("Microsoft.XMLDOM")
xmlDocument.async="false"
xmlDocument.load("classxml.xml")

     // get the root element
     var element = xmlDocument.documentElement;
     var val = element.firstChild;

     document.writeln(
         "<p>Here is the root node of the document: " +
         "<strong>" + element.nodeName + "</strong>");

     document.writeln("<p>The name of the class is " + val.firstChild.nodeValue);

     val = val.nextSibling.nextSibling;

     document.writeln("<p>The time for this course is " + val.firstChild.nodeValue);

     document.writeln("<p> do it1" );
     var mylist = element.getElementsByTagName("name");
     document.writeln("<p> do it2" + mylist.length );

     for (var i=0; i < mylist.length; i++)
     {  
         student = mylist.item(i);
         document.writeln("<p>Student " + student.firstChild.nodeValue);
        
     }

    
         -->
   </script>

   </body>
</html>
 

see it run

<html>
<body>

<script type="text/javascript">
var xmlDocument=new ActiveXObject("Microsoft.XMLDOM")
xmlDocument.async="false"
xmlDocument.load("classxml.xml")

// get the root element
     var element = xmlDocument.documentElement;
  
     document.writeln(
         "<p>Here is the root node of the document: " +
         "<strong>" + element.nodeName + "</strong>" +
         "<br />The following are its child elements:" +
         "</p><ul>" );

     // traverse all child nodes of root element
     for ( var i = 0; i < element.childNodes.length; i++ ) {
         var curNode = element.childNodes.item( i );
    
         // print node name of each child element
         document.writeln( "<li><strong>" + curNode.nodeName
           + "</strong></li>" );
     }

     document.writeln( "</ul>" );

     // get the first child node of root element
     var currentNode = element.firstChild;

     document.writeln( "<p>The first child of root node is: " +
         "<strong>" + currentNode.nodeName + "</strong>" +
         "<br />whose next sibling is:" );

     // get the next sibling of first child
     var nextSib = currentNode.nextSibling;

     document.writeln( "<strong>" + nextSib.nodeName +
         "</strong>.<br />Value of <strong>" +
         nextSib.nodeName + "</strong> element is: " );

     var value = nextSib.firstChild;

     // print the text value of the sibling
     document.writeln( "<em>" + value.nodeName + "</em>" +
         "<br />Parent node of <strong>" + nextSib.nodeName +
         "</strong> is: <strong>" +
         nextSib.parentNode.nodeName + "</strong>.</p>" );
         -->
</script>

</body>
</html>

 

see it run

[Home] [Syllabus] [Sessions] [Writing Code] [Help] [Setup] [Instructor]