0

I have searched about this. All I got was xml parsing/ Sax parser. I need a program that will download xml data. I need this for my android application development. thanks

For example i have a website localhost:8080/folder/sample.html.. How do i get a .xml file from that?

user253751
  • 50,383
  • 6
  • 45
  • 81
dotamon
  • 63
  • 3
  • 8

3 Answers3

2

Sorry if I'm not answering the question - but is it the website content, you want to download? If positive, these are similar questions where the solution may lie:

Community
  • 1
  • 1
FanaticD
  • 1,306
  • 3
  • 19
  • 35
2

try this code:

public String getXmlText(String urlXml) {
    URL url;
    InputStream is = null;
    BufferedReader br;
    String line;
    String result = null;

    try {
        url = new URL(urlXml);
        is = url.openStream();
        br = new BufferedReader(new InputStreamReader(is));

        while ((line = br.readLine()) != null) {
            result = result + line + "\n";
        }
    } catch (Exception e) {
        return "";
    } finally {
        try {
            if (is != null) is.close();
        } catch (IOException ioe) {}
    }
    return result;
}
The Badak
  • 1,982
  • 2
  • 14
  • 28
0

Try this code

import java.net.*;
import java.io.*;

class Crawle {

    public static void main(String ar[]) throws Exception {

        URL url = new URL("http://www.foo.com/your_xml_file.xml");
        InputStream io = url.openStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(io));
        FileOutputStream fio = new FileOutputStream("file.xml");
        PrintWriter pr = new PrintWriter(fio, true);
        String data = "";
        while ((data = br.readLine()) != null) {

            pr.println(data);
        }


    }
}
StarsSky
  • 6,651
  • 6
  • 37
  • 62
Simmant
  • 1,428
  • 25
  • 39