+ Start a Discussion

Recieving XML in Webservice using Rest architecture??


I wrote a webservice which uses RestRequest to recieve the xml, however I am not able to convert the recieved request into xml i.e Dom.document or xmlstreamreader, below is the webservice I wrote, I able to see the xml in the log System.debug('--->RestContext.request'+req); but How do I convert RestContext.request to dom or xmlstreamreader, as I need to parse and create record from the data??, Thanks a lot


global with sharing class CandExpJobPost_RouterV1 {

static boolean LogEvent = false;


global static String doRecieve( ) {
mydef doc3;
createjobpostfromxml parse=new createjobpostfromxml();
//System.debug('Recieved xml -->'+doc3);
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
String xml = req.requestBody.toString().trim();

//res.addHeader('Content-Type', 'text/xml');
testdomjobpost testdoc = new testdomjobpost();
String x=String.Valueof(req);




Hi Kumarhatti,


Use XMLDom to Parse the response.


for example:

your XML response in debuglog is below





then use the following code to parse it and create a record.



Management__c Members = new Management__c(); //Management is your Custom object
XMLDom responseXML = new XMLDom(res);   //Your Response as Parameter
//Get Member Details          
for(XMLdom.Element Member :responseXML.getElementsByTagName('Member')) { 
   if(Member.getValue('Name').trim() != null && Member.getValue('Name').trim() != '') {
		Members.Name= Member.getValue('Name').trim();
	if(Member.getValue('TS').trim() != null && Member.getValue('TS').trim() != '') {
		Members.Total_Salary__c= decimal.valueof(Member.getValue('TS').trim());

insert Members;


 Let me know if any issues, or if it works ,please mark it solved.