Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #49197
| 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 | <klica_sk8@hotmail.com> |
| 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 <klica_sk8@hotmail.com> |
| To | "python-list@python.org" <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 <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3852.1372199369.3114.python-list@python.org> (permalink) |
| 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 |
Show key headers only | 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
Parsing soap/xml result miguel olivares varela <klica_sk8@hotmail.com> - 2013-06-25 15:28 -0700
csiph-web