ok so my responseText contains an ‘&’ character which seems to cause problems when parsing. so I want to grab my responseText and change the ‘&‘ for ‘&‘
I’m aware responseText is a String and ideally I want to feed this back into the responseXML to parse with the new xml with &
any help much appreciated
responseXML = xmlhttp.responseXML;
var myResponseText = "<document-metadata><item><name>ccms_customer_key</name><value>0100000931012004110</value></item><item><name>ccms_customer_name</name><value>Mr Joe Bloggs</value></item><item><name>ccms_customer_salutation_name</name><value>Mr</value></item><item><name>ccms_rm_name</name><value></value></item><item><name>ccms_dms_key</name><value>2432559OEKM</value></item><item><name>ccms_customer_address</name><value>Main & Street Dublin </value></item></document-metadata>";
/*
if(myResponseText.indexOf('&') >= 0)
{
var str = myResponseText.replace(/&/g,"&");
return str;
}
*/
//old line getSession().setAttribute('LH_METADATA_XML',xmlhttp.responseText);
getSession().setAttribute('LH_METADATA_XML',myResponseText);
// extract COMP_DMS_KEY from metadata
var root = responseXML.getElementsByTagName('document-metadata').item(0);
Why not parse the string in a completely different way, such as with
DOMParseror (may be what you need due to the error)document.implementation.createHTMLDocument(""), or even just creating a HTMLDivElement and settinginnerHTML?Doing this (i.e. using text/html rather than application/xml) will mean that the parser is less strict and not be troubled by the
&whilst retaining the ability to use DOM methods.From here you can now even re-serialize and convert this to a true XML document, say
rootis your root node