I get data in XML from a web service from a connector URL, the xml contains data about people, now I have to read the names, emailids from that xml and compare with my org's contacts and so some operations. So how do I read it?

2 Answers 2


You need either Dom or XmlStreamReader class to parse your xml response. You can find sample code in the below links.

Xml parsing using XmlStreamReader:- https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_xml_streaming_reading.htm

Xml parsing using Dom:- https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_xml_dom.htm

  • 3
    Please do not post link only answers as they can lose their value if the links break, include a bit of relevant information from the linked site.
    – Dave Humm
    Oct 5, 2016 at 5:49

I did a similar thing in the past. I fixed it fist by parsing the XML retrieved from connect into JSON using xml2js library

const parser = new xml2js.Parser();
const message = await parser.parseStringPromise(xml);

The fields that you add to a DocuSign document are included deep into the json structure

const tabStatus = message.DocuSignEnvelopeInformation.EnvelopeStatus[0].RecipientStatuses[0].RecipientStatus[0].TabStatuses[0];

Then, you just need to find the element of the value that you want. In this example, I search for a field with tab label amount, and extract the value using TabValue[0]

const amount = tabStatus.TabStatus.find(field => field.TabLabel[0] == 'amount')
subscription.amount = amount.TabValue[0];

hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.