I am doing a web service call and get XML response back. I need to extract the data within the XML node and create a map out of it. The issue is not the XML but the way the data is present in the node. Below is the response I get:

<RETS ReplyCode="0" ReplyText="Operation successful">
MemberName = Member 22
User = 42870,0,Third Party,42870
Broker = 3637
MetadataVersion = 01.01.00057
MetadataTimestamp = Mon, 24 Oct 2011 12:16:01 GMT
MinMetadataVersion = 01.01.00057
MinMetadataTimestamp = Mon, 24 Oct 2011 12:16:01 GMT
OfficeList = 3637
GetMetadata = /metadata
GetObject = /GETOBJECT
Login = /LOGIN
Logout = /LOGOUT
Search = /SEARCH

I need to extract the data within the RETS-RESPONSE node and create a map out of it. The data is tab delimited. I did something like this:

Dom.Document doc = new Dom.Document();
Dom.XMLNode root = doc.getRootElement();
for(Dom.XmlNode child : root.getChildren()) {
    System.debug('child text : ' + child.getText());

I get a long string where it is impossible to determine where one key value pair ended and other began.

Is there any way to read the data from such XML node?

Thank you.

  • Does that XML come from a salesforce API ? IT's not entirely clear how this question is related to salesforce. Jun 8, 2015 at 16:52
  • 1
    No the XML does not come from Salesforce API. But I am trying to use XML class to read the data within the node. Jun 8, 2015 at 17:10
  • 1
    That XML is a poorly designed API. I'd complain if I were you.
    – sfdcfox
    Jun 9, 2015 at 5:42

1 Answer 1


Code something like this will create a map assuming the text is separated across lines:

Map<String, String> m = new Map<String, String();
for (String line : child.getText().split('\n', -1)) {
    String[] parts = line.split('=', 2);
    if (parts.size() == 2) {
        m.put(parts[0].trim(), parts[1].trim());

though the hard work would be to parse things like the timestamps if you have to.

You must log in to answer this question.

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