Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #49225
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <davea@davea.name> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.004 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'tree': 0.05; 'column': 0.07; 'parser': 0.07; 'exception,': 0.09; 'line:': 0.09; 'none)': 0.09; 'subject:xml': 0.09; 'try:': 0.09; 'xml.': 0.09; 'def': 0.12; '"0"': 0.16; 'err:': 0.16; 'wrote:': 0.18; 'library': 0.18; 'seems': 0.21; 'import': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'parse': 0.24; 'please?': 0.24; 'subject:/': 0.26; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'xml': 0.29; "i'm": 0.30; 'code': 0.31; "skip:' 10": 0.31; 'correctly.': 0.31; 'libraries': 0.31; 'there.': 0.32; 'guess': 0.33; 'url:non-standard http port': 0.33; '"the': 0.34; "i'd": 0.34; 'could': 0.34; 'except': 0.35; 'but': 0.35; 'there': 0.35; 'library.': 0.36; 'next': 0.36; "didn't": 0.36; 'url:org': 0.36; 'being': 0.38; 'expected': 0.38; 'problems': 0.38; 'feed': 0.38; 'skip:[ 10': 0.38; 'to:addr:python-list': 0.38; 'url:schemas': 0.38; 'pm,': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'remove': 0.60; 'first': 0.61; 'show': 0.63; 'real': 0.63; 'here': 0.66; 'believe': 0.68; 'received:74.208': 0.68; 'received:74.208.4.194': 0.84; 'working,': 0.84 |
| Date | Tue, 25 Jun 2013 22:34:25 -0400 |
| From | Dave Angel <davea@davea.name> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130510 Thunderbird/17.0.6 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: Parsing soap/xml result |
| References | <BAY175-W36DE10675A0A793EEA0F61DC8B0@phx.gbl> |
| In-Reply-To | <BAY175-W36DE10675A0A793EEA0F61DC8B0@phx.gbl> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Provags-ID | V02:K0:xDp0P1fo++9MbnmJVlkczEwG1hmRzqsao//rj9R9rXI idS6F1XTNseKI0RsWkb+4kFyh5SV2mmQ7OjBFmvmMnB2DlW3vm xZJ/T6tRAQa7baOEuRm0OLQCacgHgBsx0V56nC540Kh/Ovj8Sk xnHqAr4xa/KoKVWD8sFLqyNdgPVv7kKTLFf2DB0PLPAerEMCEF VYUHRB+ZSlZS3praRkEAu8oZCzSCleDSF9LtiYnY2bcWYrDdhS ER/uiXbHh9hW7m9cFa45z3q/2EK0v9+El0XOLmRYCUSltz5XQF E23s6OeaihBFrJWMhVn1JnazF98/zn3aKCEwGPbYx/Fzk1/WQ= = |
| 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.3875.1372214079.3114.python-list@python.org> (permalink) |
| Lines | 81 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1372214079 news.xs4all.nl 15893 [2001:888:2000:d::a6]:40558 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:49225 |
Show key headers only | View raw
On 06/25/2013 06:28 PM, miguel olivares varela wrote:
>
> 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
>
You don't show the whole error, but I'd guess the error is being
triggered in the line: tree = ET.fromstring(answer)
None of these libraries help when fed ill-formed xml.
The line:
<giftPkgReturn> xsi:type="xsd:string">0</giftPkgReturn">
is just bogus. I believe that line would be valid if you remove the
first ">" symbol in the line. But that's just my mental parser working,
and I didn't try to feed it to a real xml library. Note the next line
has the same problem, and there could well be other problems in there.
The fix? Get the author of the "the answer" to generate it correctly.
--
DaveA
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Parsing soap/xml result Dave Angel <davea@davea.name> - 2013-06-25 22:34 -0400
csiph-web