I have a TCP connection that sends me XML messages over a stream.
The first message I receive in the <?xml version="1.0" encoding="utf-8"?>
message.
The second is a authentication request message, which provides a seed to use when hashing my credentials to send back to the server - <session seed="VJAWKBJXJO">
.
At this point I should send a <session user="admin" password_hash="123456789">
message back to authenticate myself.
Once authenticated I will receive the desired data in the form of <Msg>data</Msg>
.
If I do not authenticate in time with the server, I receive a </session>
message, to indicate the session has been closed.
The problem is that I can't use a DOM parser because attempting to parse the <session>
tag with no end tag always throws an error, so I'm attempting to use the Xerces-c SAX parser, to perform progressive parsing of the XML.
When I receive each message I want to ideally append it to a MemBufInputSource
which contains all XML which has currently been received, then perform a parseNext
on the buffer to parse the new XML that has been received, but I can't figure out how to get it working correctly.
Is there a better way around this problem? Perhaps just using a special case for the <session></session>
messages?
Thanks