expat parsing error

Discussion in 'Python' started by kaklis@gmail.com, Jun 1, 2010.

  1. Guest

    Hi i'm doing the following:

    def start_element(name, attrs):
    print 'Start element:', name, attrs
    def end_element(name):
    print 'End element:', name
    def char_data(data):
    print 'Character data:', repr(data)

    class SimpleServer(LineReceiver): # Using Twisted

    def connectionMade(self):
    print 'Connection from: ', self.transport.client

    def connectionLost(self, reason):
    print self.transport.client, 'Disconnected'

    def dataReceived(self, line):
    """Here the XML Parser"""

    p = xml.parsers.expat.ParserCreate()

    p.StartElementHandler = start_element
    p.EndElementHandler = end_element
    p.CharacterDataHandler = char_data
    p.Parse(line, 1)

    I got the following error
    --- <exception caught here> ---
    File "/usr/lib/python2.6/site-packages/Twisted-10.0.0-py2.6-linux-
    x86_64.egg/twisted/internet/selectreactor.py", line 146, in
    _doReadOrWrite
    why = getattr(selectable, method)()
    File "/usr/lib/python2.6/site-packages/Twisted-10.0.0-py2.6-linux-
    x86_64.egg/twisted/internet/tcp.py", line 460, in doRead
    return self.protocol.dataReceived(data)
    File "stdiodemo.py", line 419, in dataReceived
    p.Parse(line, 1)
    xml.parsers.expat.ExpatError: syntax error: line 1, column 0

    The XML Message is coming in the form of:

    POST /test/pcp/Listener HTTP/1.1
    user-agent:hjahs
    Host:127.0.0.1
    Content-Length: 547

    <pttv_control_message version="1.0-M4-SNAPSHOT" build="599"
    xmlns="http://1270.0.01/pttv">
    <cmdReply>
    <code>200</code>
    <message>OK, found 5 session entries</message>
    <sessionList>
    <session>
    <id>06d4d59bfdfe10139dd874</id>
    <subscriberId>82</subscriberId>
    <deviceClass>and</deviceClass>
    </session>
    </sessionList>
    </cmdReply>
    </pttv_control_message>

    Please give me some hints
    , Jun 1, 2010
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fabian Kr?ger
    Replies:
    0
    Views:
    397
    Fabian Kr?ger
    Nov 19, 2003
  2. Bjoern Hoehrmann

    parsing XML with 'expat'

    Bjoern Hoehrmann, Aug 20, 2007, in forum: XML
    Replies:
    2
    Views:
    599
    Roman Mashak
    Aug 20, 2007
  3. sharan
    Replies:
    1
    Views:
    713
    Pavel Lepin
    Oct 26, 2007
  4. aha
    Replies:
    2
    Views:
    484
    Stefan Behnel
    Jan 23, 2009
  5. expat parsing error

    , Jun 1, 2010, in forum: Python
    Replies:
    10
    Views:
    1,681
Loading...

Share This Page