You need to sign in to do that
Don't have an account?

Convert XMl string to List Object
Hi ,
I have created a Xml string type and passed it to a Apex call out method. The result of this method is a string too. Now i would want to convert the Result Xml string into a List object. please suggest.
public class APImageUpdates {
public void APFilesMissing()
{
// Create list for Available Aupairs
List<Contact> APContacts = [Select Id,AP_Status__c,RecordTypeId from Contact where AP_Status__c ='Available' AND contact.RecordTypeId ='012300000000AHhAAM' ];
// Root of the Xml list
string XmlString = '<APFilesData>';
for(Contact contact: APContacts)
{
for(AP_Application__c APAppObj: [Select Id,Au_Pair__c,AP_Folder_Name__c,Photo1__c,Photo2__c,Photo3__c,Photo4__c From AP_Application__c where Au_Pair__c =: contact.Id])
{
if(APAppObj.IsExist_Photo1__c == false)
{
XmlString += '<APFiles>';
XmlString += '<Apfoldername>';
XmlString += APAppObj.AP_Folder_Name__c;
XmlString += '</Apfoldername>';
XmlString += '<Id>';
XmlString += APAppObj.Id;
XmlString += '</Id>';
XmlString += '<APID>';
XmlString += APAppObj.Au_Pair__c;
XmlString += '</APID>';
XmlString += '<FileUrl>';
XmlString += APAppObj.Photo1__c;
XmlString += '</FileUrl>';
XmlString += '</APFiles>';
}
if(APAppObj.IsExist_Photo2__c == false )
{
XmlString += '<APFiles>';
XmlString += '<Apfoldername>';
XmlString += APAppObj.AP_Folder_Name__c;
XmlString += '</Apfoldername>';
XmlString += '<Id>';
XmlString += APAppObj.Id;
XmlString += '</Id>';
XmlString += '<APID>';
XmlString += APAppObj.Au_Pair__c;
XmlString += '</APID>';
XmlString += '<FileUrl>';
XmlString += APAppObj.Photo2__c;
XmlString += '</FileUrl>';
XmlString += '</APFiles>';
}
if(APAppObj.IsExist_Photo3__c == false )
{
XmlString += '<APFiles>';
XmlString += '<Apfoldername>';
XmlString += APAppObj.AP_Folder_Name__c;
XmlString += '</Apfoldername>';
XmlString += '<Id>';
XmlString += APAppObj.Id;
XmlString += '</Id>';
XmlString += '<APID>';
XmlString += APAppObj.Au_Pair__c;
XmlString += '</APID>';
XmlString += '<FileUrl>';
XmlString += APAppObj.Photo3__c;
XmlString += '</FileUrl>';
XmlString += '</APFiles>';
}
if(APAppObj.IsExist_Photo4__c == false )
{
XmlString += '<APFiles>';
XmlString += '<Apfoldername>';
XmlString += APAppObj.AP_Folder_Name__c;
XmlString += '</Apfoldername>';
XmlString += '<Id>';
XmlString += APAppObj.Id;
XmlString += '</Id>';
XmlString += '<APID>';
XmlString += APAppObj.Au_Pair__c;
XmlString += '</APID>';
XmlString += '<FileUrl>';
XmlString += APAppObj.Photo4__c;
XmlString += '</FileUrl>';
XmlString += '</APFiles>';
}
}
}
//Close root Xml
XmlString += '</APFilesData>';
ServiceMethod(XmlString);
}
//Service Method
public static void ServiceMethod(string xml)
{
string ServiceResult = '';
WebServiceOrg.AjaxSoap Service = new WebServiceOrg.AjaxSoap();
ServiceResult = Service.GAPNetworkImages(xml);
Checkboxupdate(ServiceResult);
}
public static void Checkboxupdate(string xml)
{
List<AP_Application__c> APAppObj = new List<AP_Application__c>();
}
I need to convert the resulting Xml and populate the results to List<AP_Application__c>. can someone please suggest
Thank you.
Hello,
Well there is no any direct method to do this. You have to use XML parse to acieve this. Salesforce provide XMLDom class to parse an XML.
Think this will help you.