tags:

views:

73

answers:

4

I have an XML file located at a location such as

http://example.com/test.xml

I'm trying to parse the XML file to use it in my program with xPath like this but it is not working.

Document doc = builder.parse(new File(url));

How can I get the XML file?

+1  A: 

Get rid of the new File():

Document doc = builder.parse(url);
laz
A: 

It's much easier with a XMLPullParser ... you don't have to deal with this event stuff and can quickly pick up some keywords ... I'm using it too ... only a couple of code lines :)

http://developer.android.com/reference/org/xmlpull/v1/XmlPullParser.html

Regarding HTTP and files have a look here http://stackoverflow.com/questions/3011770/download-a-file-with-defaulthttpclient-and-preemptive-authentication

Nils
+1  A: 

A little more detail, based on laz answer:

String urlString = "http://example.com/test.xml";
URL url = new URL(urlString);
Document doc = builder.parse(url);
santiagobasulto
builder.parse cannot handle a URL.
Travis
Uhmm, ok, i made a mistake. But that's the way you should do it. First open a connection with a URL, read the content and then parse it. Sorry for that brother.
santiagobasulto
A: 
File fileXml = new File(url);

DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document document = parser.parse(fileXml);

it should go

Erick