Skip to content Skip to sidebar Skip to footer

Jquery Parse Xml From Single And Multiple Tags

Got a problem returning the text from an xml node. It all needs to be dynamic. Here is the xml: Some ins text.

Solution 1:

To get the text content of your option nodes try this....

Firstly, your xml isn't valid. I've added a root node

var xml = "<root><instructions>Some ins text.</instructions><options><option>1.png</option><option>2.png</option><option>3.png</option><option>4.png</option></options><noOfOptions>4</noOfOptions></root>",
    xmlDoc = $.parseXML( xml ),
    $xml = $( xmlDoc ),
    $options = $xml.find("option"); // get all option nodes

Then to get each option value using jquery .each

$.each($options, function() {
    console.log($(this).text());
});  

Hope that helps

Fiddle: http://jsfiddle.net/JohnMcNulty/vRf9Z/

Post a Comment for "Jquery Parse Xml From Single And Multiple Tags"