I have a response that comes from server side in xml format (partial like below)
<list>
<Response>
<cfgId>903</cfgId>
<recommendations>
<Rule>
<name>Env SSA_RB_RESTART</name>
<category>none</category>
<severity>warning</severity>
<ruleEvalResult>true</ruleEvalResult>
<actionResult>Setting SSA_RB_RESTART=0 will cause RuleBase corruption.Kindly unset this environment variable and
restart the IIR server</actionResult>
</Rule>
</recommendations>
</Response>
<Response>
<cfgId>903</cfgId>
<recommendations>
<Rule>
<name>SSAOPTS (+Ltd) setting</name>
<category>none</category>
<severity>warning</severity>
<ruleEvalResult>true</ruleEvalResult>
<actionResult>
Please note that it is not recommended to have SSAOPTS=+Ltd in case of the
Production environment.</actionResult>
</Rule>
</recommendations>
</Response>
</list>
update
I get the main Response
tag with xml=$(xmldata); var resp_x = $(xml).find('Response').text();
and then I am trying to replace with below
resp_x = resp_x.replace(/</g,"<");
resp_x = resp_x.replace(/>/g,">");
var rule_x = $(resp_x).find('name').text();
alert(rule_x);
but it gives me blank, please help me fetch severity
.
UPDATE with my answer
var xmlString=xmlToString(xmldata);
xmlString=xmlString.replace(/(<)/g,"<").replace(/(>)/g,">");
xml=StringtoXML(xmlString);
//now I can do my operations here
$(xml).find('Response').each(function(){
console.debug($(this).find('severity').text());
});
function xmlToString(xmlObj) {
if (navigator.appName == "Netscape")
{
return (new XMLSerializer()).serializeToString(xmlObj);
}
if (navigator.appName == "Microsoft Internet Explorer")
{
return xmlObj.xml;
}
}
function StringtoXML(text){
if (window.ActiveXObject){
var doc=new ActiveXObject('Microsoft.XMLDOM');
doc.async='false';
doc.loadXML(text);
} else {
var parser=new DOMParser();
var doc=parser.parseFromString(text,'text/xml');
}
return doc;
}
Try like this
Hope this helps
Next example can help you:
Update: next code does not need to replace
<
and>
for gettingseverity
:http://jsfiddle.net/ZpYac/
You're converting the returned XML to a jQuery object too early and then doing the replace wrong. Try something like this:
In the
replace()
, you need both theg
(global) andm
(multi-line) flags. See the documentation on String.replace() for details.