Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes XML and Related Technologies and the fly likes retrieve XML data from URL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "retrieve XML data from URL" Watch "retrieve XML data from URL" New topic

retrieve XML data from URL

Steve Jiang
Ranch Hand

Joined: May 17, 2004
Posts: 107
is there simple way to retrieve XML data from a existing URL directly? after I use getDocumentElement to get element from URL, could I output the contents of element in a simple way without parse the subnodes? so I can output the contents of URL in a general way without the concern for the inside content of XML?


William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12761
A URL is not an XML document so I assume you mean to open a URLConnection to a XML document and read it. See and HttpURLConnection. Just open the connection and getInputStream.

If all you want is to echo the contents, just read the InputStream and write to whatever suits your fancy.

If you need to do something with the XML, you can just feed the InputStream to a DocumentBuilder to get a DOM.
If you just want the content text without the tags, use an SAX parser.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: retrieve XML data from URL
Similar Threads
Unmarshall with JAXB Error
Trying to iterate an ArrayList of Beans
Loading problem with t:inputFileUpload
XML over http
How to read from XSD generated database and put that data into XML file.