Trying to get XML from an URL

Previously, I used the the XML file from the assets folder. The app can read it very well. The next step I want put this XML on the web server. But at this stage, the app cannot recognize any data. It confused me couple of days.

AssetManager asset = getAssets();
InputStream input ="student.xml");
List<Student> list = ParserByPULL.getStudents(input);

Open in new window

Everything works fine if the file in assets folder. Then I tried to get it from an URL.

String path = "";
URL url = new URL(path);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
InputStream input = url.openConnection().getInputStream(); 
List<Student> list = ParserByPULL.getStudents(input);

Open in new window

I have added the permission of connecting the INTERNET at manifest file.
After these steps, I have run the app. Unfortunately, nothing shows on the screen. There are some permission warnings in LogCat, but it shows all time when I fetch the file from Assets. So I dont think the problem is the permission.  
Does anyone has an idea about this? Thank you.
Who is Participating?
KRUNAL TAILORConnect With a Mentor Freelance Mobile DeveloperCommented:
Hi ron154,

First let me know what are you trying to achieve?

If you wan't to send xml file on server(means upload on server) in that case this below links will help you,


if you wan't to get xml file from server (means download from server), because your code suggest it you are trying to download it from server. may be i am wrong but, if you wan't to grab the xml file from server in that case you can do this.

uri = new HttpGet("");
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 

Open in new window


1) By using HTTP Request getting the XML content.
2) Parsing the XML content and retrieve DOM element in the XML.
3) Retrieve each element child element value by using node name of element.

Follow this link:

Thanks & Regards,
Krunal T. Tailor
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.