Goofy
Goofy

Reputation: 6128

Parse the xml from URL

guys i have an xml in an URL and i need to parse that xml

below is my xml

this is how i am parsing

InputStream in = new FileInputStream(file);
builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
doc = builder.parse(in, null);


            NodeList audio = doc.getElementsByTagName("point");
            int len = audio.getLength();
            Toast t = Toast.makeText(getApplicationContext(), "Length is "+len, 0);
            t.show();

            for (int i = 0; i < len; i++) {

                Node singleTerminalNode1 = audio.item(i);
                Element secondlevel = (Element)singleTerminalNode1;
                NodeList value2Nodes = (secondlevel).getElementsByTagName("file");
                String audioxml = ((Element)value2Nodes.item(0)).getAttribute("name");
                System.out.println("got the value from audioxml "+audioxml);
                Toast toast = Toast.makeText(getApplicationContext(), "Downloaded to Sdcard/varun/"+audioxml, 0);
                toast.show();

            }

But i need to parse from URL how to aceheive this

Upvotes: 0

Views: 2580

Answers (1)

Thommy
Thommy

Reputation: 5407

URL url;
url = new URL("http://.....");
URLConnection ucon = url.openConnection();
ucon.connect();
url.openStream()

The url.openStream() returns an InputStream. So replace your new FileInputStream(file); with it and it should do fine.

Upvotes: 1

Related Questions