Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #49197

Parsing soap/xml result

From miguel olivares varela <klica_sk8@hotmail.com>
Subject Parsing soap/xml result
Date 2013-06-25 15:28 -0700
Newsgroups comp.lang.python
Message-ID <mailman.3852.1372199369.3114.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

I try to parse a soap/xml answer like:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Body>
      <ns1:giftPkgResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://192.168.2.135:8490/gift-ws/services/SRV_GIFT_PKG">
         <giftPkgReturn soapenc:arrayType="xsd:string[2]" xsi:type="soapenc:Array" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
            <giftPkgReturn> xsi:type="xsd:string">0</giftPkgReturn">
            <giftPkgReturn> xsi:type="xsd:string">OK</giftPkgReturn> xsi:type="xsd:string">
         </giftPkgReturn>
      </ns1:giftPkgResponse>
   </soapenv:Body>
</soapenv:Envelope>


here is my code
---------------------------------------------------------------------------
import xml.etree.ElementTree as ET
import re

def parse(answer):
    print"\nANSWER<<", answer
    try:
        tree = ET.fromstring(answer)
        result = {}
        for item in tree.getiterator():
            if item.tag in ['giftPkgReturn', 'giftPkgReturn']:
                result[item.tag] = item.text

        print "get<<%s" % result.get('status', None)
        resp1 = result.get('giftPkgReturn', None)
        resp2 = result.get('giftPkgReturn', None)

        if (resp1 == "0" and resp2 == "OK"):
            logger.info("Successful")
            print "OK:"
            return 0
        else:
            logger.info("Unsuccessful")
            return -1

     except Exception, Err:
            print "\nERROR <<", str(Err)
            return -1

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

I got the error, i'm no a xml expert but it seems than the answser does not look like a pure xml.  i also tried with lxml instead of xml library but the result is te same

xml lib
ERROR << not well-formed (invalid token): line 5, column 77

lxml
ERROR << expected '>', line 5, column 37


could you help me to correctly parse the answer please?

regards,
Miguel

 		 	   		  

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Parsing soap/xml result miguel olivares varela <klica_sk8@hotmail.com> - 2013-06-25 15:28 -0700

csiph-web