The XMLDOM object works in either synchronous or asynchronous (default?) mode. When working in synchronous mode the XMLDOM.load(...) function will wait until the document is fully loaded:
Code:
xmlDocumentObject = new ActiveXObject("Microsoft.XMLDOM")
xmlDocumentObject.async = false;
xmlDocumentObject.load("category.xml")
// at this point you can use the document
But when loading documents asynchronous the script will continue to run even before the document has been fully loaded:
Code:
xmlDocumentObject = new ActiveXObject("Microsoft.XMLDOM")
xmlDocumentObject.async = true;
xmlDocumentObject.load("category.xml")
// at this point the document might still be loading, this it's unsafe to use the document
In the latter case you would need to wait until the document is fully loaded. Using the alert function is not a (good) solution. What you should do is to listen for events thrown by the XMLDOM object:
Code:
xmlDocumentObject = new ActiveXObject("Microsoft.XMLDOM")
// set up asynchronous mode
xmlDocumentObject.async = true;
// register listener for event
xmlDocumentObject.onreadystatechange = function () {
if (oXmlDom.readyState == 4) {
//this part is executed when the document is ready
}
};
// load document
xmlDocumentObject.load("category.xml")
- petter