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

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.

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, 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
Jon Mountjoy_Jon Mountjoy_
If you want your 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:

To grab it, I use the following code:
public void ws() {
 Http http       = new Http(); 
 HttpRequest req = new HttpRequest(); 
 HttpResponse res = http.send(req); 
 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();
return fin;

result should be bar1 bar2.

Hope that helps!


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