Question

I have a webservice call. which send the response in the encrypted format as reponse text. when I decrypt the response text I will get an XML data. Now I want to parse this xml data. Can any one please give some idea

var respon = decrypted.toString(CryptoJS.enc.Utf8);

alert(respon);

var xml = jQuery(respon);
alert(xml.find('line:first').text());
Was it helpful?

Solution

Put your response xml inside $ function. Like lets say you got :

var str = '<NewDataSet> <Table> <line>1</line> <Trimestre>Octubre-Diciembre</Trimestre> <currency>EU?</currency> <growth>6.7</growth> <balanced>4.73</balanced> <moderate>2.98</moderate> </Table> <Table> <line>1</line> <Trimestre>Octubre-Diciembre</Trimestre> <currency>US$</currency> <growth>10.76</growth> <balanced>7.57</balanced> <moderate>5.44</moderate> </Table> </NewDataSet> ';

var xml = jQuery(str);
console.log(xml.find('line:first').text())

Use debugger or console.log to further iterate your $(xml)

OTHER TIPS

I'm not sure what 'parse' means exactly. But if 'parse' means fetch several data from some xml, the code below would help.

var data = [];

$.ajax({
    url: "some-url/sample.xml",
        async: true,
        cache: true,
        dataType:"xml",
        success: function(xml){
            $(xml).find('item').each(function(i){
                data.push({
                    'id': $(this).find("id").text(),
                    'title'    : $(this).find("title").text()
                });
            });
    },
    error: function(err){
        console.log(err);
    }
});    

sample.xml

<item>
<id>1</id>
<title>Alasteir</title>
</item>
<item>
<id>2</id>
<title>Bob</title>
</item>
<item>
<id>3</id>
<title>John</title>
</item>
<item>
<id>4</id>
<title>Mary</title>
</item>
<item>
<id>5</id>
<title>Tom</title>
</item>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top