Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: How to Convert IO Stream to XML Document

Thread Tools

Re: How to Convert IO Stream to XML Document

Posts: n/a
On Sep 10, 12:20*pm, jakecjacobson <(E-Mail Removed)> wrote:
> I am trying to build a Python script that reads a Sitemap file and
> push the URLs to a Google Search Appliance. *I am able to fetch the
> XML document and parse it with regular expressions but I want to move
> to using native XML tools to do this. *The problem I am getting is if
> I use urllib.urlopen(url) I can convert the IO Stream to a XML
> document but if I use urllib2.urlopen and then read the response, I
> get the content but when I use minidom.parse() I get a "IOError:
> [Errno 2] No such file or directory:" error


This may not be helpful, but I note that you are doing two different
things with your requests, and judging from the documentation, the
objects returned by urllib and urllib2 openers do not appear to be the
same. I don't know why you are calling urllib.urlopen(url) and
urllib2.urlopen(request), but I can tell you that I have used urllib2
opener to retrieve a web services document in XML and then parse it
with minidom.parse().

> THIS WORKS but will have issues if the IO Stream is a compressed file
> def GetPageGuts(net, url):
> * * * * pageguts = urllib.urlopen(url)
> * * * * xmldoc = minidom.parse(pageguts)
> * * * * return xmldoc
> # THIS DOESN'T WORK, but I don't understand why
> def GetPageGuts(net, url):
> * * * * request=getRequest_obj(net, url)
> * * * * response = urllib2.urlopen(request)
> * * * * response.headers.items()
> * * * * pageguts =

Did you note the documentation says:

"One caveat: the read() method, if the size argument is omitted or
negative, may not read until the end of the data stream; there is no
good way to determine that the entire stream from a socket has been
read in the general case."

No EOF marker might be the cause of the parsing problem.


Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Convert DVD with subtitle stream to DivX with same subtitle stream(selectable) malise Software 1 04-17-2007 09:15 AM
Refer to an XML document from within an XML document Manish Hatwalne XML 1 07-13-2004 10:24 AM
WebService returns XML in a String - how can I 'convert' this to an XML document? Ben Turner ASP .Net 2 01-02-2004 05:20 AM
Help on including one XML document within another XML document using XML Schemas Tony Prichard XML 0 12-12-2003 03:18 PM