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
  • 57,427
  • 7
  • 48
  • 90
dotamon
  • 75
  • 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,416
  • 4
  • 20
  • 36
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
  • 2,010
  • 2
  • 16
  • 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,721
  • 6
  • 38
  • 63
Simmant
  • 1,477
  • 25
  • 39