+ Start a Discussion
satyaprakash palsatyaprakash pal 

Parsing xml to REST API APEX class

Hello everyon
I have created one Rest api for creating Contacts. How I can test my rest api by passing xml . is ther any way that I test my rest api. I tested using json parser in workbench but I am not able to test my rest api apex code by parsing xml.

//apex class    
    Global static String candidateInformation(List<Candidate> Candidates, String reqSessionId) {

Note: How I can read the xml in Rest api apex class ?
//Parsing xml request
<?xml version="1.0" encoding="UTF-8"?>
              <Phone>string or int</Phone>        
Trail Head 33Trail Head 33
public class DomDocument {

    // Pass in the URL for the request
    // For the purposes of this sample,assume that the URL
    // returns the XML shown above in the response body
    public void parseResponseDom(String url){

       string xml = '<OrderDetails>
       Dom.Document doc = new Dom.Document();

        //Retrieve the root element for this document.
        Dom.XMLNode ordDtls = doc.getRootElement();

        String OrderDetailId= ordDtls.getChildElement('OrderDetailId', null).getText();
        String prdCode = ordDtls.getChildElement('ProductCode', null).getText();
        // print out specific elements
        System.debug('OrderDtlID: ' + OrderDetailId);
        System.debug('Prod Code: ' + prdCode );

        // Alternatively, loop through the child elements.
        // This prints out all the elements of the address
        for(Dom.XMLNode child : ordDtls.getChildElements()) {

Hi satyaprakashpal,
Try this 
please Mark it as best Answer if it helps you.

Thanks ,