I looked at Convert String to XML Document in JavaScript but I could not found a solution in my case, can somebody help me in my situation.
I have a string like below, I want to convert it to an XML Object, How can I do that?
<list>
<Response>
<cfgId>280</cfgId>
<recommendations><Rule>
<name>simple rule</name>
<category>none</category>
<severity>warning</severity>
<ruleEvalResult>true</ruleEvalResult>
<actionResult> Current value of maxfilesperproc is 32
increase it to 1024</actionResult>
</Rule></recommendations>
</Response>
</list>
Readable version of above xml
<list>
<Response>
<cfgId>280</cfgId>
<recommendations>
<Rule> <name>simple rule</name> <category>none</category> <severity>warning</severity> <ruleEvalResult>true</ruleEvalResult> <actionResult>Current value of maxfilesperproc is 32
increase it to 1024</actionResult> </Rule>
</recommendations>
</Response>
</list>
Updated, Here is what i tried.
var xml;
$.post("/csm/rules.action",
{ sessiontoken: sessiontoken,
cfgid: cfgid},
function(xmldata)
{
xml=$(xmldata);
}
);
var htmlTable = $('<table></table>');
$(xml).find('Response').each(function(){
var cid = $(this).find('cfgId').text();
alert(cid+", "+cfgid);
if(cid==cfgid) {
// Now grab the entitiy string
var newXmlString = $(xml).find('recommendations').text();
// Convert the entities to HTML and return a jQuery object
var newXml = $("<div/>").html(newXmlString);
// NOW we can get at the inner XML
var ruleseverity=$(newXml).find('severity').text();
if(ruleseverity=="warning") {
var rulename=$(newXml).find('name').text();
var rulecategory=$(newXml).find('category').text();
var ruleresult=$(newXml).find('ruleEvalResult').text();
var ruleactionresult=$(newXml).find('actionResult').text();
htmlTable.append('<tr><td>RuleName:'+rulename+'</td><td>RuleResult: '+ruleactionresult+'</td></tr>');
}
}
});
I am adding htmlTable
later in the code '<div class="block">'+htmlTable+'</div>'
I does not alerts at all