Click here to Skip to main content
15,892,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I want to read XML file from URL and retrieve data from that XML file and view in android apps. Is there any way to access like that. Please help me if you know means.
Posted

Hello,

Below is a small code snippet demonstrating how it can be done on android.
Java
HttpGet uri = null;
Document doc = null;
StatusLine status = null;
HttpResponse resp = null;
DocumentBuilder builder = null;
DefaultHttpClient client = null;
DocumentBuilderFactory factory = null;

uri = new HttpGet("YOUR XML FILE URL GOES HERE");

client = new DefaultHttpClient();
resp = client.execute(uri);
status = resp.getStatusLine();
if (status.getStatusCode() == "200") {
    factory = DocumentBuilderFactory.newInstance();
    builder = factory.newDocumentBuilder();
    doc = builder.parse(resp.getEntity().getContent());
    ...
    // Your code for reading XML doc 
}

You will also find following articles very useful.

Regards,
 
Share this answer
 
Comments
ssyuvaraja 28-May-13 7:25am    
Hi, Thank you.
I am getting exception at this line
resp = client.execute(uri);
can you please help me.
Prasad Khandekar 28-May-13 8:52am    
Which exception are you getting?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900