XML is returned as a string, not an object

I do not quite understand why this will not work. I thought it was easy to interact with XML, but I couldn't help but feel that XML markup was causing a problem. I know its validate XML, but still:

XML 79.xml

<TREE xmlns:autn="http://schemas.autonomy.com/aci/"> <ITEM id="753" name="Report an IT Issue for a Corporate Finance Application." link="http://ithelp-remedy.gsk.com/ars/ITHelpHDsubmit_Application/SubmitProblemTicket.asp?qSummary=CORPFINANCEIT"> <HELPLINKS/> </ITEM> </TREE> 

It is also worth noting that all of the XML that I will return should not contain more details in the xml header?

JQuery

  $.ajax({ url:'xml/79.xml', dataType : 'xml', success: function(data){ console.info(data); } }); 

This will not return me the object to play back :( How can I get it so that I can easily play using data

+4
source share
2 answers

Try the following:

 $.ajax({ url:'xml/79.xml', dataType : 'text', success: function(data){ //I'm adding the xml tags alright, but I don't think you //really need to, or you could just put a check. var omgXmlObj = $($.parseXML('<xml>' + data + '</xml>')); console.log(omgXmlObj.find('TREE')); console.log(omgXmlObj.find('TREE').attr('xmlns:autn')); } }); 
+1
source

According to jQuery documentation

if you want the text response to be processed as XML, use "text xml" for dataType

try to do it like this:

 $.ajax({ url:'xml/79.xml', dataType : 'text xml', success: function(data){ console.info(data); } }); 

Judging by the source code (_ajaxConvert function), it seems that there is no conversion at all, if only one data type is specified, I could be wrong, although

+1
source

All Articles