• Login or register

discuss.effbot.org

  • Popular
  • Recent
  • 1 point by MarcusSchorn 1 year ago on General Discussion for effbot.org 2 children

    It is just an oberservation.
    This is something we get as a result from a webservice:
    --------------------------------------------------------
    from elementsoap.ElementSOAP import namespace_parse
    import elementtree.ElementTree as ET

    xmltext = """<?xml version="1.0" encoding="ISO-8859-1" ?><ns0:Envelope xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/"><ns0:Body><ns1:getMasterDataResponse xmlns:ns1="XeriAPI"><resultList command="getMasterData" version="1.0">
    <user>
    <title value="Jan"/>
    </user>
    <doctype>
    <title value="Richtlinie T"/>
    <title value="Formular"/>
    </doctype>
    <process>
    <title value="Controlling"/>
    </process>
    <department>
    <title value="Integral Development GmbH"/>
    </department>
    <category>
    <title value="Beschaffung / Purchase"/>
    </category>
    <responsibleUnit>
    <title value="Support"/>
    </responsibleUnit>
    <location>
    <title value="Stockholm"/>
    <title value="Paris"/>
    <title value="Hamburg"/>
    </location>
    </resultList></ns1:getMasterDataResponse></ns0:Body></ns0:Envelope>
    """
    class Myfile:
    isread = False
    def read(self, *args, **kw):
    if Myfile.isread:
    return ""
    Myfile.isread = True
    return xmltext

    try:
    res = ET.parse(Myfile())
    print "ET.parse worked:", res
    except:
    print "ET.parse error!"

    try:
    res = namespace_parse(Myfile())
    print "namespace_parse worked:", res
    except:
    print "namespace_parse error!"

    --------------------------------------------------------

    • parent
    • reply
    • 1 point by effbot 1 year ago 1 child

      Thanks for the sample. I'll look into this as soon as I find the time.

      Update: Your sample code is setting a class attribute (Myfile.isread) instead of an instance attribute (self.isread). Since class attributes are shared between all instances of a class, the second Myfile instance will always return an empty string -- which causes the second parser to raise a "ParseError: no element found" exception. If I fix that, both parsers successfully parse that XML snippet.

      • link
      • reply
      • 1 point by MarcusSchorn 1 year ago 0 children

        Opps, you are right. I have originally used it in the running system. And cutted some XML away. I will check again.

        • link
        • reply
  • Widget
  • Recent Comments
  • Leaders
Powered by