Parse XML using APEX
string xmlstring = '<?xml version="1.0" encoding="UTF-8"?><OTPResp status="1" ts="2016-06-09T17:24:46" txn="20160609172112021" resCode="ad3198bda02e3742571c855b50c576de2e8c8641" errCode="" errMsg=""></OTPResp>';
DOM.Document xmlDOC = new DOM.Document();
xmlDOC.load(xmlstring);
DOM.XMLNode rootElement = xmlDOC.getRootElement();
//outxmlstring=String.valueof(xmlDOC.getRootElement().getChildAttribute());
outxmlstring=String.valueof(rootElement.getAttributeValue('status',null));
outxmlstring1 =String.valueof(rootElement.getAttributeValue('resCode',null));
system.debug('++++outxmlstring '+outxmlstring );
Output: outxmlstring = 1
outxmlstring1 = ad3198bda02e3742571c855b50c576de2e8c8641
DOM.Document xmlDOC = new DOM.Document();
xmlDOC.load(xmlstring);
DOM.XMLNode rootElement = xmlDOC.getRootElement();
//outxmlstring=String.valueof(xmlDOC.getRootElement().getChildAttribute());
outxmlstring=String.valueof(rootElement.getAttributeValue('status',null));
outxmlstring1 =String.valueof(rootElement.getAttributeValue('resCode',null));
system.debug('++++outxmlstring '+outxmlstring );
Output: outxmlstring = 1
outxmlstring1 = ad3198bda02e3742571c855b50c576de2e8c8641
Comments
Post a Comment