0

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 = asset.open("student.xml");
List<Student> list = ParserByPULL.getStudents(input); 

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

String path = "http://fthgyj.tup632.cnaaa11.com/student.xml";
URL url = new URL(path);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(5000);
conn.setRequestMethod("GET");
InputStream input = url.openConnection().getInputStream(); 
List<Student> list = ParserByPULL.getStudents(input);

I have added the permission of connecting the INTERNET at manifest file. Does anyone has an idea about this?

krishna
  • 4,069
  • 2
  • 29
  • 56
user3421634
  • 1
  • 1
  • 2

2 Answers2

0

I think you need to call

conn.connect();
InputStream input = conn.getInputStream();

And then check if you got the xml fetched:

BufferedReader reader = new BufferedReader(new InputStreamReader(input));
StringBuilder builder = new StringBuilder();
String line;

while ((line = reader.readLine()) != null) {
    builder.append(line);
}
reader.close();
Log.d("tag", "output: " + builder.toString());
vilpe89
  • 4,656
  • 1
  • 29
  • 36
0

Try this to Pull and Parse the XML file from URL,

http://www.javacodegeeks.com/2010/11/boost-android-xml-parsing-xml-pull.html

sais
  • 803
  • 6
  • 15