Nick Kahn
Nick Kahn

Reputation: 20078

how to extract element from xml/string

i am using 3rd party api and this is what is its returning me:

<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>
\u000a
<errorNotification>
\u000a\u0009
<message>invalid company code<\/message>
\u000a
<\/errorNotification>

my question is: how can just extract the <message> from the above string/xml?

Upvotes: 0

Views: 917

Answers (1)

Sotiris
Sotiris

Reputation: 40066

var xml = '<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\u000a<errorNotification>\u000a\u0009<message>invalidcompanycode<\/message>\u000a<\/errorNotification>',
xmlDoc = $.parseXML( xml ),
$xml = $( xmlDoc ),
message= $xml.find( 'message' ).text();


alert(message);

Demo: http://jsfiddle.net/ycLms/

Upvotes: 3

Related Questions