FAQ
I'm using SOAPpy to access weather data from the NOAA National Digital
Forecast Database XML Web Service [1] and I've been having
trouble figuring out how to parse the data.

The response comes back as XML document but when I check it with
type(result) it shows the the response is a string. Does anyone have any
suggestions on getting relevant data? I've attached a sample SOAP response
to this post.

Thanks,
-Sean
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070831/69697610/attachment.htm
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: response.txt
Url: http://mail.python.org/pipermail/tutor/attachments/20070831/69697610/attachment.txt

Search Discussions

  • Alan Gauld at Sep 1, 2007 at 4:09 pm
    "Sean Cronin" <seancron at gmail.com> wrote
    The response comes back as XML document but when I check it with
    type(result) it shows the the response is a string.
    Thats right the string is the XML document, just as if you had read it
    from a file with the read() method.
    Does anyone have any suggestions on getting relevant data?
    You need to parse the xml.

    The classic way to do that is using DOM or sax parsing, but
    Python now has the ElementTree parser which is usually
    much easier to use. Look at the module docs and for a lot
    more detail visit the ElementTree homepage:

    http://effbot.org/zone/element-index.htm

    HTH,


    --
    Alan Gauld
    Author of the Learn to Program web site
    http://www.freenetpages.co.uk/hp/alan.gauld
  • Eric Brunson at Sep 1, 2007 at 4:24 pm

    Alan Gauld wrote:
    "Sean Cronin" <seancron at gmail.com> wrote

    The response comes back as XML document but when I check it with
    type(result) it shows the the response is a string.
    Thats right the string is the XML document, just as if you had read it
    from a file with the read() method.

    Does anyone have any suggestions on getting relevant data?
    You need to parse the xml.

    The classic way to do that is using DOM or sax parsing,
    Bleah. ;-)
    but
    Python now has the ElementTree parser which is usually
    much easier to use. Look at the module docs and for a lot
    more detail visit the ElementTree homepage:

    http://effbot.org/zone/element-index.htm
    I've used ElementTree a tiny bit, but preferred BeautifulSoup as it
    seemed more "pythonic" to me. You should look at both and pick the one
    that suits you. BeautifulSoup has the advantage of not choking on
    choking on XML that is not well formed.

    e.
  • Dave Kuhlman at Sep 1, 2007 at 6:09 pm

    On Sat, Sep 01, 2007 at 10:24:24AM -0600, Eric Brunson wrote:
    Alan Gauld wrote:
    "Sean Cronin" <seancron at gmail.com> wrote

    The response comes back as XML document but when I check it with
    type(result) it shows the the response is a string.
    Thats right the string is the XML document, just as if you had read it
    from a file with the read() method.

    Does anyone have any suggestions on getting relevant data?
    You need to parse the xml.

    The classic way to do that is using DOM or sax parsing,
    Bleah. ;-)
    I don't understand this. The response comes back as the value of a
    function/method call. You should not have to look at XML (text) at
    all, unless something goes wrong and you need to do debugging.
    This is the point of using SOAPpy. XML is the underlying (and
    mostly hidden) data representation that is sent "across the wire".
    But, you deal with Python and SOAPpy. It translates your function
    calls into XML, sends it to a SOAP server, receives an (XML)
    response, and translates that XML response back into Python
    objects.

    Currently, I do not have SOAPpy installed. But last time I used
    it, I did not parse XML.

    For an example, in the SOAPpy distribution, look at
    tests/cardClient.py. It makes SOAP requests, and receives the
    responses to those requests, but it does not (directly) generate or
    parse XML. SOAPpy does that for you.

    You have most likely already looked at those examples. So, maybe
    there is something that I don't understand about your question?

    Dave
  • Alan Gauld at Sep 1, 2007 at 10:13 pm
    "Dave Kuhlman" <dkuhlman at rexx.com> wrote
    The response comes back as XML document but when I check it with
    type(result) it shows the the response is a string.
    This is the point of using SOAPpy. XML is the underlying (and
    mostly hidden) data representation that is sent "across the wire".
    But, you deal with Python and SOAPpy. It translates your function
    calls into XML, sends it to a SOAP server, receives an (XML)
    response, and translates that XML response back into Python
    objects.
    That's how it usually works where the return values are simple objects
    like strings, integers, dates, even lists of things. But Web Services
    are sometimes defined to return an XML document as the return object.
    This is usually because the exact content is undefined or there is a
    lot
    of it in complex structures. When that happens Python hands you a
    string, which happens to be an XML document. The XML envelope that
    surrounds the SOAP message is correctly stripped away by SOAPpy
    but the string thats left is itself an XML document.

    Its nothing to do with SOAPpy per se, any SOAP implementation
    will do the same, it's what the web service returns.

    HTH,

    --
    Alan Gauld
    Author of the Learn to Program web site
    http://www.freenetpages.co.uk/hp/alan.gauld

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouptutor @
categoriespython
postedAug 31, '07 at 10:54p
activeSep 1, '07 at 10:13p
posts5
users4
websitepython.org

People

Translate

site design / logo © 2022 Grokbase