Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder7.xlned.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'tree': 0.05; 'column': 0.07; 'exception,': 0.09; 'none)': 0.09; 'subject:xml': 0.09; 'try:': 0.09; 'xml.': 0.09; 'def': 0.12; '"0"': 0.16; 'err:': 0.16; 'library': 0.18; 'seems': 0.21; 'import': 0.22; 'to:name:python-list@python.org': 0.22; 'print': 0.22; 'error': 0.23; 'parse': 0.24; 'please?': 0.24; 'subject:/': 0.26; 'tried': 0.27; 'xml': 0.29; "i'm": 0.30; 'code': 0.31; "skip:' 10": 0.31; 'url:non-standard http port': 0.33; 'could': 0.34; 'except': 0.35; 'skip:s 30': 0.35; 'but': 0.35; 'url:org': 0.36; 'expected': 0.38; 'skip:& 10': 0.38; 'skip:[ 10': 0.38; 'to:addr:python-list': 0.38; 'url:schemas': 0.38; 'received:65.54': 0.38; 'received:65.54.190': 0.38; 'received:bay0.hotmail.com': 0.38; 'skip:& 20': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'skip:x 10': 0.40; 'here': 0.66 X-TMN: [GBRbGRVYV+EzJayVBEeykvHOiYtBySgG] X-Originating-Email: [klica_sk8@hotmail.com] Content-Type: multipart/alternative; boundary="_896900a4-e08d-4694-944d-ad60e3300cf2_" From: miguel olivares varela To: "python-list@python.org" Subject: Parsing soap/xml result Date: Tue, 25 Jun 2013 15:28:19 -0700 Importance: Normal MIME-Version: 1.0 X-OriginalArrivalTime: 25 Jun 2013 22:28:20.0477 (UTC) FILETIME=[4BE762D0:01CE71F3] X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 153 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1372199369 news.xs4all.nl 16000 [2001:888:2000:d::a6]:57347 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:49197 --_896900a4-e08d-4694-944d-ad60e3300cf2_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I try to parse a soap/xml answer like: xsi:type=3D"xsd:string">0 xsi:type=3D"xsd:string">OK xsi:= type=3D"xsd:string"> here is my code --------------------------------------------------------------------------- import xml.etree.ElementTree as ET import re def parse(answer): print"\nANSWER<<"=2C answer try: tree =3D ET.fromstring(answer) result =3D {} for item in tree.getiterator(): if item.tag in ['giftPkgReturn'=2C 'giftPkgReturn']: result[item.tag] =3D item.text print "get<<%s" % result.get('status'=2C None) resp1 =3D result.get('giftPkgReturn'=2C None) resp2 =3D result.get('giftPkgReturn'=2C None) if (resp1 =3D=3D "0" and resp2 =3D=3D "OK"): logger.info("Successful") print "OK:" return 0 else: logger.info("Unsuccessful") return -1 except Exception=2C Err: print "\nERROR <<"=2C str(Err) return -1 ---------------------------------------------------------------------------= ------------- I got the error=2C i'm no a xml expert but it seems than the answser does n= ot 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=2C column 77 lxml ERROR << expected '>'=2C line 5=2C column 37 could you help me to correctly parse the answer please? regards=2C Miguel = --_896900a4-e08d-4694-944d-ad60e3300cf2_ Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable

I try to parse a soap/xml an= swer like:

<=3Bsoapenv:Envelope xmlns:soapenv=3D"http://schemas.xm= lsoap.org/soap/envelope/" xmlns:xsd=3D"http://www.w3.org/2001/XMLSchema" xm= lns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance">=3B
 =3B&nbs= p=3B <=3Bsoapenv:Body>=3B
 =3B =3B =3B =3B =3B &= lt=3Bns1:giftPkgResponse soapenv:encodingStyle=3D"http://schemas.xmlsoap.or= g/soap/encoding/" xmlns:ns1=3D"http://192.168.2.135:8490/gift-ws/services/S= RV_GIFT_PKG">=3B
 =3B =3B =3B =3B =3B =3B = =3B =3B <=3BgiftPkgReturn soapenc:arrayType=3D"xsd:string[2]" xsi:typ= e=3D"soapenc:Array" xmlns:soapenc=3D"http://schemas.xmlsoap.org/soap/encodi= ng/">=3B
 =3B =3B =3B =3B =3B =3B =3B = =3B =3B =3B =3B <=3BgiftPkgReturn>=3B xsi:type=3D"xsd:strin= g">=3B0<=3B/giftPkgReturn">=3B
 =3B =3B =3B =3B&nb= sp=3B =3B =3B =3B =3B =3B =3B <=3BgiftPkgReturn&g= t=3B xsi:type=3D"xsd:string">=3BOK<=3B/giftPkgReturn>=3B xsi:type=3D"= xsd:string">=3B
 =3B =3B =3B =3B =3B =3B = =3B =3B <=3B/giftPkgReturn>=3B
 =3B =3B =3B =3B&= nbsp=3B <=3B/ns1:giftPkgResponse>=3B
 =3B =3B <=3B/soapenv= :Body>=3B
<=3B/soapenv:Envelope>=3B


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

def parse(answer= ):
 =3B =3B =3B print"\nANSWER<=3B<=3B"=2C answer
&nb= sp=3B =3B =3B try:
 =3B =3B =3B =3B =3B = =3B =3B tree =3D ET.fromstring(answer)
 =3B =3B =3B = =3B =3B =3B =3B result =3D {}
 =3B =3B =3B = =3B =3B =3B =3B for item in tree.getiterator():
 =3B&nbs= p=3B =3B =3B =3B =3B =3B =3B =3B =3B = =3B if item.tag in ['giftPkgReturn'=2C 'giftPkgReturn']:
 =3B = =3B =3B =3B =3B =3B =3B =3B =3B =3B =3B=  =3B =3B =3B =3B result[item.tag] =3D item.text

&nbs= p=3B =3B =3B =3B =3B =3B =3B print "get<=3B<=3B= %s" % result.get('status'=2C None)
 =3B =3B =3B =3B = =3B =3B =3B resp1 =3D result.get('giftPkgReturn'=2C None)
 = =3B =3B =3B =3B =3B =3B =3B resp2 =3D result.get('g= iftPkgReturn'=2C None)

 =3B =3B =3B =3B =3B = =3B =3B if (resp1 =3D=3D "0" and resp2 =3D=3D "OK"):
 =3B = =3B =3B =3B =3B =3B =3B =3B =3B =3B =3B= logger.info("Successful")
 =3B =3B =3B =3B =3B = =3B =3B =3B =3B =3B =3B print "OK:"
 =3B =3B=  =3B =3B =3B =3B =3B =3B =3B =3B =3B re= turn 0
 =3B =3B =3B =3B =3B =3B =3B else: =3B =3B =3B =3B =3B =3B =3B =3B =3B&n= bsp=3B =3B logger.info("Unsuccessful")
 =3B =3B =3B = =3B =3B =3B =3B =3B =3B =3B =3B return -1
 =3B =3B =3B =3B except Exception=2C Err:
 =3B&nbs= p=3B =3B =3B =3B =3B =3B =3B =3B =3B = =3B print "\nERROR <=3B<=3B"=2C str(Err)
 =3B =3B =3B&nb= sp=3B =3B =3B =3B =3B =3B =3B =3B return -1
=
-----------------------------------------------------------------------= -----------------

I got the error=2C i'm no a xml expert but it seem= s than the answser does not look like a pure xml. =3B i also tried with= lxml instead of xml library but the result is te same

xml lib
ER= ROR <=3B<=3B not well-formed (invalid token): line 5=2C column 77
lxml
ERROR <=3B<=3B expected '>=3B'=2C line 5=2C column 37

could you help me to correctly parse the answer please?

regard= s=2C
Miguel

= --_896900a4-e08d-4694-944d-ad60e3300cf2_--