+ Start a Discussion
Thewalking faceThewalking face 

read and parse an xml file using web service


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 {    
        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
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.