Subject: Loop in XML DOM?
Posted By: omallec Post Date: 11/26/2003 6:37:53 PM
Wondering if anyone can help me include a loop into my xml using dom.  Whenever I try to launch this page the system crashes.


<html>
    <head>
        <title>BQI DOM Example</title>
        <script language="JavaScript">
        
function getActiveClasses()
{

xmlDocumentObject = new ActiveXObject ("Microsoft.XMLDOM")
xmlDocumentObject.load("bqiclasses.xml")

var bqiclassesNode, classNode, courseNode, statusNode, displayText

bqiclassesNode = xmlDocumentObject.documentElement
classNode = bqiclassesNode.firstChild
courseNode = classNode.firstChild.nextSibling.nextSibling.text
statusNode = classNode.lastChild.text

for (var i = 0; statusNode = '1'; i++)
{

displayText = "Active Classes: " + courseNode + " - " + "Status: " + statusNode
displayDIV.innerHTML = displayText
}
}
</script>
    </head>
    <body>
        <input type="button" value="Display Active Classes" onclick="getActiveClasses()">
            <br />
            <div id="displayDIV"/>
        </input>
    </body>
</html>
Reply By: armmarti Reply Date: 11/27/2003 12:46:17 AM
You have an infinite loop there. Instead, use this construct:

for(var i = 0; i < theNode.childNodes.length; ++i) {
  currentChild = theNode.childNodes[i];
}


Regards,
Armen
Reply By: joefawcett Reply Date: 11/27/2003 3:40:01 AM
And also...
"Microsoft.XmlDom" is severely deprecated as you don't know what dom class you'll get. If you can control the environment you use install version 4.0 sp2 from msdn and use "Msxml2.DomDocument.4.0" or failing that most machines will have version 3, "Msxml2.DomDocument.3.0".
If you use "Microsoft.XmlDom" you could get the pre XPath parser, it only supports XSLPattern which has a different syntax entirely for searches.


--

Joe
Reply By: omallec Reply Date: 11/27/2003 8:16:06 AM
Thanks Armen, Thanks Joe!  I am new to xml and only a novice with JavaScript so I appreciate your tips.  I kept thinking about this all night and I wondered if I had an infinite loop.  Again, thank you VERY MUCH!


Go to topic 6956

Return to index page 997
Return to index page 996
Return to index page 995
Return to index page 994
Return to index page 993
Return to index page 992
Return to index page 991
Return to index page 990
Return to index page 989
Return to index page 988