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
Ad_InfosysAd_Infosys 

XML Stream Reader

If I have a large XML from other external application.

I have the XML on the server i.e. my local machine. the location is something like

C:\\Documents and Settings\\rahul_arora\\Desktop\\book.xml

Now I want this to be utilised in SFDC. All the examples to read the XML have the XML code converted to string and then instantiate the XMLStreamReader.

How do I do in my case. Kindly suggest the elaborated approach.

FLopesNHOFLopesNHO
Hi Ad_Infosys,

I have the same problem as you. I don't know where to start! Do we create a HTML page (or php, asp.net) to hanlde the data and then use an s-control to mash-up with salesforce? Or we have to create an APEX code to deal directly with the data from the xml? I'm a bit confused... Any help on this issue is most welcome! Sorry i'm not helping at all...

Best regards
FLopes
Jon Mountjoy_Jon Mountjoy_
If you want your force.com app to reach the data, you need to put it somewhere on the web and go and grab it from your program. You could use a SOAP request for example.  Or for a light weight version, just dump it on a web server.   I've put some simple XML here:
http://www.jonmountjoy.com/foo.xml

To grab it, I use the following code:
public void ws() {
 Http http       = new Http(); 
 HttpRequest req = new HttpRequest(); 
 req.setEndpoint('http://www.jonmountjoy.com/foo.xml'); 
 req.setMethod('GET'); 
 HttpResponse res = http.send(req); 
 System.debug(res.getBody());
 XmlStreamReader reader = res.getXmlStreamReader();
 result = parsed(reader);
}
 
Then I parsed it like so:

String parsed (XmlStreamReader readr) {
 String fin = 'Parsed foo values: ';
 while (readr.hasNext()) {
  if (readr.getEventType() == XmlTag.CHARACTERS) {
    fin += readr.getText();
  }
  readr.next();
 }
return fin;
}

result should be bar1 bar2.

Hope that helps!
Jon

Ad_InfosysAd_Infosys

Thanks dear.

This seems to be an attractive approach.

Is it possible if we copy the XML in a trigger. This code will convert the XML to a string variable. Then pass the same variable in the XMLStreamReader() class. This will on the lines of the code specified in apex reference guide.

 

 

Best Regards

Aman.