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