How to switch java code from using local XML file to URL of an XML file

404 Views Asked by At

I have written web application that reads an XMl file parses it and does some work.

Rather than using a local file, I'd like to use a URL of the XML file ( something like http://mydomain.com/daily-extract.xml )

This is what my code looks like:

 private String xmlFile = "D:\\default-user\\WINXP\\Desktop\\extract-jan10d.xml";

 SAXBuilder builder =  new SAXBuilder("org.apache.xerces.parsers.SAXParser");
 // Parse the specified file and convert it to a JDOM document
 document = builder.build(new File(xmlFile));

 Element root = document.getRootElement();

How can I switch from a file to a URL on the internet

1

There are 1 best solutions below

0
On

Try to replace this line :

document = builder.build(new File(xmlFile));

By :

document = builder.build(new File(new URI("http://mydomain.com/daily-extract.xml")));