• Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading XML from Web  RSS feed

Amit Dua
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I need your help to solve a problem related to parsing XML Stream.
We have an application which reads data in form of XML over HTTP.Earlier , I was using parse method of DocumentBuilder , something like
document = builder.parse(PULL_URL);
But every now and then , it hands at this line i.e. at parse method.
I read good words about HTTPClient from apache on this forum and started using that .present code looks like something :
XMLReader xr = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
//SaxSpiceUnmarshaller handler = new SaxSpiceUnmarshaller();
// Parse each file provided on the
// command line.
//new code added to avoid URLConnection glitches
HostConfiguration hc=new HostConfiguration();
client = new HttpClient();
method = new GetMethod("query/smsinxml.asp");
int statusCode = -1;
int attempt = 0;
// We will retry up to 3 times.
while (statusCode == -1 && attempt < 11) {
// execute the method.
statusCode = client.executeMethod(method);
catch (HttpRecoverableException e)
System.err.println("A recoverable exception occurred,retrying. " + e.getMessage());
attempt = attempt +1;
catch (IOException e)
System.err.println("Failed to download file.");
attempt = attempt+1;
// Check that we didn't run out of retries.
if (statusCode == -1) {
System.err.println("Failed to recover from exception.");
//close the database connection and raise NHF Alert

bin=method.getResponseBodyAsStream() ;
// Release the connection.
xr.parse(new InputSource(bin));
I am still facing the same problm.Application hangs every now and then reading from that URL and starts after long duration(sometimes 30mins) . is it not safe reading XML as inputstream ? I have document of size not more than 1 MB and using SAX API to handle the XML nodes one by one, without first loading the whole document in memory.
I have tried all things which i can think of.Please help me out in this.

Thanks in Advance !
Lasse Koskela
Posts: 11962
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
XML parsers handle InputStreams just fine. The problem must be at the networking level (unless there is a bug report for your particular parser version) so I'm moving this post over to the Sockets and Internet Protocols forum.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!