...

View Full Version : JS:DOM:XML:AJAX and Whitespace



voxecho
10-16-2006, 10:37 PM
hiya all, am running into a problem with my attempt to learn Ajax.

The problem that i am running into is that if the xml being loaded has any whitespace - it is not totally ignored, but it does ignore some of the nodes. :\

example the following XML is loaded in using XMLHttpRequest:


<rformats>
<format>
<name>F1</name>
<nonCont>true</nonCont>
</format>
<format>
<name>F2</name>
<nonCont>true</nonCont>
</format>
<format>
<name>F3</name>
<nonCont>true</nonCont>
</format>
<rformats>



/*
*/ When i attempt to look at the return:

alert(x.childNodes[0].hasChildNodes()) //true
alert(x.childNodes[0].childNodes[0].hasChildNodes()) //false
alert(xmlFormats.childNodes[0].childNodes[0].childNodes[0].nodeValue) // error


however with the following XML


<rformats><format><name>F1</name><nonCont>true</nonCont></format><format><name>F2</name><nonCont>true</nonCont></format><format><name>F3</name><nonCont>true</nonCont></format></rformats>




/*
*/ i get

alert(x.childNodes[0].hasChildNodes()) //true
alert(x.childNodes[0].childNodes[0].hasChildNodes()) //true
alert(xmlFormats.childNodes[0].childNodes[0].childNodes[0].hasChildNodes()) // true
alert(xmlFormats.childNodes[0].childNodes[0].childNodes[0].childNodes[0].nodeValue) // F1


Oh, and of coarse, it's working fine in IE... but not in FireFox...

Question #2...

is there any benifits to using


[ie] var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
[ns] var xmlDoc=document.implementation.createDocument("","",null);
xmlDoc.load("note.xml");

over

the XMLHttpRequest object?


thanks in advance

-Echo



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum