Simple REST API for XML response in Salesforce

Simple REST API for XML response in Salesforce

Remote Site Settings:

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 ); 

Leave a Reply