-
May 11th, 2007, 10:43 AM
#1
why to call alert() between xml parsing in javascript
Hello Dear
I am parsing my xml using below mention code.but i donot know should use alert("ffff")because if i donot use alert("ffff") it's throws an error "object required"
You can also try this code with own xmlfile in two ways
1. By putting comment before "alert("ffff")
2. By removing the comment "alert("ffff")
I am sure that if you will use the code with first method you will get the error.
<SCRIPT LANGUAGE="JavaScript">
function readXMLData()
{
var xmlDocumentObject, sessionNode, committeeNode1,
attendeesNode
var firstNameNode, lastNameNode, displayText
var attributes, statusSenator
xmlDocumentObject = new ActiveXObject("Microsoft.XMLDOM")
xmlDocumentObject.load("category.xml")
alert("fffff")
sessionNode = xmlDocumentObject.documentElement
alert(sessionNode.firstChild.xml);
committeeNode1 = sessionNode.firstChild
committeeNode = committeeNode1.firstChild
attributes = committeeNode.attributes
CategoryId = attributes.getNamedItem("CategoryId")
outputText = committeeNode.firstChild.nodeValue
+ ' ' + committeeNode.firstChild.nodeValue
+ "'s status is: " + CategoryId
displayDIV.innerHTML=outputText
}
</SCRIPT>
I am waiting for someones response.
Thanks
-
May 11th, 2007, 12:39 PM
#2
Re: why to call alert() between xml parsing in javascript
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|