aspose file tools*
The moose likes Java in General and the fly likes Parsing an xml response from a url using STAX Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Parsing an xml response from a url using STAX" Watch "Parsing an xml response from a url using STAX" New topic
Author

Parsing an xml response from a url using STAX

swati mppy
Greenhorn

Joined: Jul 03, 2011
Posts: 7
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

Joined: Oct 25, 2008
Posts: 2700

You're first reading everything from the stream and than pass the stream to stax? Are you sure that is correct?


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
swati mppy
Greenhorn

Joined: Jul 03, 2011
Posts: 7
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
 
subject: Parsing an xml response from a url using STAX