Best way to parse XMPP-like XML streams?
Posted
by codethief
on Stack Overflow
See other posts from Stack Overflow
or by codethief
Published on 2010-04-30T00:37:34Z
Indexed on
2010/04/30
7:17 UTC
Read the original article
Hit count: 195
I am working on a server application which receives data over a TCP socket in an XMPP-like XML format, i.e. every child of the <root>
element essentially represents one separate request (stanza). The connection is closed as soon as </root>
is received.
I do know that I must use a stream parser like SAX, somehow. Though, for convenience, I'd prefer to have a tree-like interface to access each stanza's child elements. (The data sent with every request is not large so I think it makes sense to read each stanza as a whole.)
What's the best way to realize that in Python (preferably v3)?
This is the code I'd like to build it in. Feel free to point me in a totally different direction to solve this issue.
import socketserver
import settings
class MyServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
pass
class MyRequestHandler(socketserver.StreamRequestHandler):
def handle(self):
pass
if __name__ == '__main__':
server = MyServer((settings.host, settings.port), MyRequestHandler)
server.serve_forever()
© Stack Overflow or respective owner