javascript - xmlHttp.responseXML seems empty - .responseText is correctly filled -


i trying read xml file object using javascript parse information , transform data in it.

the xml file formed (and in same domain), pasted several validators , came without errors, shouldn't source of error.

i trying access file via ajax / xmlhttprequest. here's code snippet of relevant part:

if (xmlhttp)     {         var url = xmlfile;         xmlhttp.open("get", url, true);         xmlhttp.onreadystatechange = function()          {             if (xmlhttp.readystate == 4)             {                 //alert(xmlhttp.responsetext);                 var xmldata = xmlhttp.responsexml;                 var txt="";                 var x=xmldata.getelementsbytagname("rs:data");                  alert(x.length);                  (i=0;i<x.length;i++)                 {                     txt=txt + x[i].childnodes[0].nodevalue + "<br>";                 }                }         }         xmlhttp.send();     } 

now problem variable "x" comes empty (length = 0). when alert responsetext however, can see whole xml file in alert message, seems rather strange me.

the xml file looks this:

<xml xmlns:s='uuid:bdc6e3f0-6da3-11d1-a2a3-00aa00c14882'  xmlns:dt='uuid:c2f41010-65b3-11d1-a29f-00aa00c14882'  xmlns:rs='urn:schemas-microsoft-com:rowset'  xmlns:z='#rowsetschema'> <s:schema id='rowsetschema'> <s:elementtype name='row' content='eltonly' rs:commandtimeout='30'>   <s:attributetype name='ows_art' rs:name='art' rs:number='1'>      <s:datatype dt:type='string' dt:maxlength='512' />   </s:attributetype> </s:elementtype> </s:schema>   <rs:data>     <z:row [...] />   </rs:data> </xml> 

what want data stored under node , learn

var x=xmldata.getelementsbytagname("rs:data"); 

should that. reason can think of .responsexml comes empty, however, there no definite way check, because if alert(xmlhttp.reponsexml) tells me, object returned, not contents of it...

does have idea why whole thing doesn't work? find confusing is, .responsetext works fine...

rs:data not tag name. tag name data in urn:schemas-microsoft-com:rowset namespace (as specified xmlns:rs='urn:schemas-microsoft-com:rowset').

you should use namespace-aware dom method.

var x = xmldata.getelementsbytagnamens("urn:schemas-microsoft-com:rowset", "data"); 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

inno setup - TLabel or TNewStaticText - change .Font.Style on Focus like Cursor changes with .Cursor -