I am trying to parse through an XML which looks something like This is a xml response of an image which i need to render in my page,can somebody help me out to parse this through XmlStreamReader .

<?xml version="1.0" encoding="UTF-8"?>
 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing">
   <wsa:MessageID soapenv:mustUnderstand="0"> uuid:c39fe700-7ebe-11e4-bcd2-833631db0ec0</wsa:MessageID>
   <wsa:To soapenv:mustUnderstand="0">http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>

   <GetObjectResponse xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
   <GetObjectResponse xsi:type="ns1:GetObjectResult" xmlns:ns1="http://s3.amazonaws.com/doc/2006-03-01/">
This is a reponse of an Image....... 
  • DOM Document is easier to use. Do you have a reason that you want to use XmlStreamReader instead?
    – Keith C
    Dec 8, 2014 at 11:26
  • Not specific . I want to parse this response to get to it . If you have any idea about DOM Document , could you please share it . Stucked and want the help
    – JJoseph
    Dec 8, 2014 at 12:16

1 Answer 1


With no error checking (such as checking the nesting of the elements and checking the status code) something like this should work:

String envNs = 'http://schemas.xmlsoap.org/soap/envelope/';
String docNs = 'http://s3.amazonaws.com/doc/2006-03-01';

String xml = ...;
Dom.Document doc = new Dom.Document();
String data = doc
        .getChildElement('Body', envNs)
        .getChildElement('GetObjectResponse', docNs)
        .getChildElement('GetObjectResponse', docNs)
        .getChildElement('Data', docNs)

where the main method used is getChildElement.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .