It's not a secret anymore!
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
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: 124
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: 13036
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.
I agree. Here's the link:
subject: retrieve XML data from URL
It's not a secret anymore!