I have an xml string that I need to pull a value from using only JavaScript. Here's an example of the xml string:
<RequestVars>
<BuyerCookie>O7CPHFP7AOY</BuyerCookie>
<Extrinsic name="CostCenter">670</Extrinsic>
<Extrinsic name="UniqueName">catalog_tester</Extrinsic>
<Extrinsic name="UserEmail">catalog_tester@mailinator.com</Extrinsic>
</RequestVars>
And I need to get the email address from it (i.e. catalog_tester@mailinator.com). I have a way to pull the value for a given unique element, such as getting O7CPHFP7AOY for BuyerCookie using this function:
function elementValue(xml, elem) {
var begidx;
var endidx;
var retStr;
begidx = xml.indexOf(elem);
if (begidx > 0) {
endidx = xml.indexOf('</', begidx);
if (endidx > 0)
retStr = xml.slice(begidx + elem.length,
endidx);
return retStr;
}
return null;
}
But now, I need a way to look up the value for the "Extrinsic" element with the value "UserEmail" for attribute "name". I've seen a couple ways to accomplish this in JQuery but none in JavaScript. Unfortunately, for my purposes, I can only use JavaScript. Any ideas?