+ Start a Discussion
saikrishna.Gsaikrishna.G 

Parsing XML response



<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Header/><soapenv:Body><p889:basicChecksDetailsResponse xmlns:p889="http://comexp.ibm.com"><basicChecksDetailsReturn>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;ExportEROData xmlns=&quot;http://w3.test.com/xmlns/ibmww/ff/sdf/ews/erodata&quot;
    xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://w3.test.com/xmlns/testww/ff/sdf/ews/erodata https://w3-206-beta1.w3-gslbdst.test.com/isc/esd/ibmexpws/schemas/ExportEROData_0101.xsd&quot;&gt;
    &lt;ExportChecksPassed&gt;true&lt;/ExportChecksPassed&gt;
    &lt;ExportUnderReview&gt;false&lt;/ExportUnderReview&gt;
    &lt;ExportLocations&gt;
        &lt;ExportLocationPassed&gt;US&lt;/ExportLocationPassed&gt;
    &lt;/ExportLocations&gt;
&lt;/ExportEROData&gt;
</basicChecksDetailsReturn></p889:basicChecksDetailsResponse></soapenv:Body></soapenv:Envelope>
I need "ExportChecksPassed" ,"ExportUnderReview" values 
<Saket><Saket>
Hi saikrishna.G,

Please try these link 

https://webkul.com/blog/parsing-xml-file-apex/
https://developer.salesforce.com/forums/?id=906F0000000BP4qIAG


Which can help you parsing this xml document but you want data from only two xml tags then I think you can use String methods to get them like as it is not an appropriate way to do but it is much better from parsing whole xml to get data from only 2 xml tags.

For Example u want to find the data from ExportChecksPassed xml tag
 
String s = '<ExportChecksPassed>';

integer indexFirst = xmlResponse.indexOf('<ExportChecksPassed>');
Integer indexSecond = xmlResponse.indexOf('</ExportChecksPassed>');

String data = xmlResponse.substring(indexFirst+s.length(), indexSecond-1);

xmlResponse is a response u r getting in XML.

I hope it will help u :)

if your problem get solved then please mark it as a best answer :P


 
<Saket><Saket>
A small change in a code 
 
String s = '<ExportChecksPassed>';

integer indexFirst = xmlResponse.indexOf('<ExportChecksPassed>');
Integer indexSecond = xmlResponse.indexOf('</ExportChecksPassed>');

String data = xmlResponse.substring(indexFirst+s.length(), indexSecond);

 
<Saket><Saket>
HI SaiKrishna,

Please Let me know whether your problem solved or not
saikrishna.Gsaikrishna.G
Hi Sanket,

Thanks for the reply but I wnated to use the XML praser I have already done by using String 

Thanks,
Saikrishna.Garnepudi