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
Thewalking faceThewalking face 

read and parse an xml file using web service

Hello, 

I'm a beginner to apex, I want to create a web service to attach and parse an xml file. My file is hosted in an FTP server. The goal is to retrieve the XML file to insert the data into a salesforce object.
I try with the code below: 

webservice static String parse(String url) {
    
    DOM.Document doc = new DOM.Document();     
      try {    
        doc.load(url);       
        DOM.XMLNode root = doc.getRootElement();
        String message = 'File find';        
        return message;    
      } 
      // catch error
      catch (System.XMLException e) {      
        return e.getMessage();    
      }    
    } 

But it doesn't work with the url (C:\files\file.xml)

Can you help me please ?
Thank's in advance
sunny.sfdcsunny.sfdc
You need to pass xml as string into doc.load() method.
Refer this link: https://salesforce.stackexchange.com/questions/60770/xml-parsing-using-apex-in-salesforce
 
Thewalking faceThewalking face
Hi, Thank you for your reply. My need is to pass the XML file as a parameter in my Webservice (and not the xml text as a string) and then parse the xml file to insert the data in an object.