aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Problem using Microsoft.XMLDOM, getting status as 'undefined' Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Problem using Microsoft.XMLDOM, getting status as Watch "Problem using Microsoft.XMLDOM, getting status as New topic
Author

Problem using Microsoft.XMLDOM, getting status as 'undefined'

Kiran Joshi
Ranch Hand

Joined: Sep 04, 2005
Posts: 54
<code snippet>

function setCombo(mytext)
{
alert('setting the combo');

var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");

xmlDoc.async="false";

xmlDoc.loadXML(mytext);

document.write("<br>Error Code: "); document.write(xmlDoc.parseError.errorCode);

document.write("<br>Error Reason: "); document.write(xmlDoc.parseError.reason);

document.write("<br>Error Line: "); document.write(xmlDoc.parseError.line) ;

while (xmlDoc.readyState!=4)
{
}

alert('ready state is '+xmlDoc.readyState);

if(xmlDoc.readyState==4)
getValues(xmlDoc);
}


function getValues(xmlDoc)

{
if (xmlDoc.readyState==4)
alert("XML file loaded!")
else
alert("XML file NOT loaded! "+xmlDoc.readyState)

xmlObj=xmlDoc.documentElement;

alert('The status for dom is '+xmlDoc.statusText);

}
</code snippet>

in above code snippet, in the last alert in function getValues() , I'm getting status as 'undefined'.

I expect status to be 200 so that I can parse the xml string.

can anybody tell me what wrong might be happening here.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61654
    
  67

"Kiran JJJ",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Kiran Joshi
Ranch Hand

Joined: Sep 04, 2005
Posts: 54
Sorry for violating the rule unknowingly.

I've changed my name Bear, Thanks !
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Are you loading this on a server or on your local file system (not localhost)?

Eric
Pavan Keely
Ranch Hand

Joined: Jun 30, 2006
Posts: 62
Kiran,

I don't think it matters whether you are loading the XML from local file system or not. Because loadXML will take XML string not the URL.

I observed few things in the code snippet you presented. Here are the things:

1. You need not check for readyState when you are using for synchronous loading of XML (async = false).
2. You can use onreadystatechange for MSXML.XMLDocument ActiveX object instead of writing a loop to check for readyState = 4. Here is the sample piece of code:

var xmlDoc;

function loadXML( mytext )
{
xmlDoc = new ActiveXObject("MSXML.DOMDocument");
xmlDoc.async= true;
xmlDoc.onreadystatechange = loaded;
var res = xmlDoc.loadXML( mytext );
//error checking, if res == true, success else, failed.
}

function loaded()
{
if( xmlDoc.readyState == 4 )
alert("loaded");
}

Pavan Keely


Pavan Keely<br /><a href="http://keelypavan.blogspot.com" target="_blank" rel="nofollow">http://keelypavan.blogspot.com</a>
Kiran Joshi
Ranch Hand

Joined: Sep 04, 2005
Posts: 54
Thanks Pavan,Eric for your replies.

So the final conclusion that I can say is ,

1) if xmlDoc.async=false , I do not need to check for the readyState , as browser will interpret the next statement only after it is ready

2) if at all I use xmlDoc.async=true , I can use the callback method xmlDoc.onreadystatechange to check for the availability of the loaded document.

So I do not need to use both these things at a time,one out of these two will work.

Please confirm.

Also which one is recommended in which situation ? synchronus or asynchronus ? Any guidelines ?
Pavan Keely
Ranch Hand

Joined: Jun 30, 2006
Posts: 62
Kiran,

Yes, your understanding is correct.

Personally I prefer using async=true because even if it takes time to parse the XML, UI will not get locked. But not to worry, if you can not use asynchronous processing, it doesnt matter much because you are loading the XML as string.

Pavan Keely
Kiran Joshi
Ranch Hand

Joined: Sep 04, 2005
Posts: 54
Thanks for this
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem using Microsoft.XMLDOM, getting status as 'undefined'