This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Parsing an xml response from a url using STAX

 
swati mppy
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am sending a xml request through java code and getting the xml response using the below code:
Now I need to parse the xml response using STAX so I have written a method for parsing:
and in the parse() I have reader = factory.createXMLEventReader(connection.getInputStream());

However I am getting the following error:
javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1] Message: Premature end of file. at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:593) at com.sun.xml.internal.stream.XMLEventReaderImpl.nextEvent(XMLEventReaderImpl.java:85)

Can someone please advise me where I am going wrong here?

Thanks,

swati
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're first reading everything from the stream and than pass the stream to stax? Are you sure that is correct?
 
swati mppy
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I found the answer, before passing the inputstream, i first read it. Once the inputstream is read, it is closed automatically. Hence the xml parsing fails.
If i comment out the BufferedReader reading part and straight pass the inputstream to the parser, the code is working fine.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic