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

Comments

Popular posts from this blog

Salesforce Spring 16 Release Exam (Maintenance Exam Q&A) for Developer 201 Admin

Show Hyper Link On Add Error in Salesforce Trigger

Show the Success Message before Redirecting the Detail page on Visualforce Page