Simple REST API for XML response in Salesforce

Sample code:

Map < String, String > mapCustomer = new Map < String, String >();
String endpoint = 'http://www.thomas-bayer.com/sqlrest/CUSTOMER/1/';
HTTP h = new HTTP();
HTTPRequest req = new HTTPRequest();
req.setEndPoint(endpoint);
req.setMethod('GET');
HTTPResponse res = h.send(req);
Dom.Document doc = res.getBodyDocument();
Dom.XMLNode customer = doc.getRootElement();
for(Dom.XMLNode child : customer.getChildElements()) {
       mapCustomer.put(child.getName(), child.getText());
}
system.debug(mapCustomer);

Cheers!!!

No comments:

Post a Comment