• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"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
 
Kiran Joshi
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for violating the rule unknowingly.

I've changed my name Bear, Thanks !
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you loading this on a server or on your local file system (not localhost)?

Eric
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Kiran Joshi
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for this
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic