function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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    
@Httppost
    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"?>
-<Candidates>
   -<Candidate>
            <JobID>string</JobID>
             <EmailAddress>string</EmailAddress>
              <FirstName>string</FirstName>
              <LastName>string</LastName>
              <Phone>string or int</Phone>        
             -<CoverLetter>
                   -<![CDATA[string]]>
              </CoverLetter>
              -<ResumeText>
                    -<![CDATA[string]]>
              </ResumeText>
             -<Base64Stream>
                   -<![CDATA[string]]>
               </Base64Stream>
     </Candidate>
</Candidates>
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>
                            <OrderDetailID>2584</OrderDetailID>
                            <GiftWrapCost>0.0000</GiftWrapCost>
                            <GiftWrapNote/>
                            <ProductCode>800006</ProductCode> 
                           </OrderDetails>';
       Dom.Document doc = new Dom.Document();
       doc.load(xml);

        //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()) {
           System.debug(child.getText());
        }
    }
}

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

Thanks ,
karthik