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

                                          
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to