We help IT Professionals succeed at work.

Parsing XML result from WS  using JQuery

Medium Priority
Last Modified: 2013-11-18
I am returning the following pseudo xml from a webservice:

 <orderr><stfuffa> </stuffa><stuffb></stuffb></order>

I am using jquery to try to parse out the "Stuff"

success: function(msg) {
    alert(msg.d); //shows me what I expected to come back in the XML, xml looks good
    var random =$(msg.d).find('stuffb').text(); //when I do this in an alert it outputs nothing...
    alert(random);  //this is empty and the problem

This code was working fine for me in Firefox.  I have tried using : jquery.xml2json.js to get the results and failed at that as well.  I don't really care how I get the data parsed out the msg, as long as it works in both browsers I'm fine.  I am kinda new to JQuery and really like it so far, but if t can't parse in both firefox and IE it's worthless to me.  Judging by all the information available on the net, there must be a workaround or I'm doing it wrong.
Watch Question


comment on the xml:  

there is always only one <Order> in the <Orders> .  There is no need to loop through the xml to get data for each order

can i see the full xml?


Theres a Base64 string in the xml, so heres a short version

      <Path></Path>   --this is always empty


> var random =$(msg.d).find('stuffb').text(); //when I do this in an alert it outputs nothing...
you are looking for 'stuffb', but that isnt in the xml? are you trying to match a node?

oops, nevermind about my previous comment.

i believe that you found a bug. Reading the documentation on text() at http://docs.jquery.com/Attributes/text clearly states that the method works on xml and html. Probably your best bet is to fill out a bug report to the jquery developers.

The test case would be something like:

var s = "<Orders>" +
                  "   <Order>" +
                  "       <OrderNo>12345</OrderNo>" +
                  "       <Path>this is the path value</Path>" +
                  "       <Base64>asdfasdfasdf.....sgdfgsdfg</Base64>" +
                  "  </Order>" +

this clearly works in firefox, but explorer seems to choke on it.

http://dev.jquery.com/newticket is where you can issue the bug report


I have a created a ticket, I'll post the results when available.
Any news on this issue?  I ran into this issue recently... I'm looking for any workarounds.

What's the ticket# for this issue?

Explore More ContentExplore courses, solutions, and other research materials related to this topic.