1 Reply Latest reply on Dec 11, 2013 9:44 PM by rp0428

    Reset/Resuse XMLEventReader?




      I'd like to reuse or reset a XMLEventReader.


      The problem:



      is quite expensive, in my scenario up to 800ms.


      The inputstream is created from a socket connection. The server socket sends XML data and sometimes "aborts" the XML structure in the middle and sends a new XML document. This is planned and I know when it happens.


      But if I just reuse the XMLEventReader, it throws:

      javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,395]

      Message: Verarbeitungsanweisungsziel, das "[xX][mM][lL]" entspricht, ist nicht zulässig.


      because the old XML document was not finished/closed, and the reader does not expect a new XML declaration.


      If I just create a new XMLEventReader it works, but it is slow.


      I also tried to use BufferedInputStreamReader and its reset and skip method, but I get exceptions, too.


      Any ideas?

        • 1. Re: Reset/Resuse XMLEventReader?
          I also tried to use BufferedInputStreamReader and its reset and skip method, but I get exceptions, too.

          Haven't worked with those classes but the issue is NOT going to be the stream itself; it will be the internal configuration and status info in the event reader class that was instantiated.


          The XMLEventReader class is just an interface so you won't have any options with it; only the exposed methods are available and there is none for 'reset' or the like.


          The only possible workaround would be to debug the code and find out exactly what implementing class the factory is returning. Then examine that class to see if it has a 'reset' or similar method. It would also need to have a method for reinitializing an instance to a new stream. You could cast the interface to the actual class type and then call those methods that are not exposed via the interface.


          If part of the instance creation consists of actually reading the initial part of the stream then you have no workarounds; a new stream would have to be read by the instance and that would only happen if there were a method in the actual concrete class you could call as I mentioned above.