ElementTree should parse string and file in teh same way

James Matthews nytrokiss at gmail.com
Mon Dec 31 14:31:25 EST 2007


When dealing with files you pass it an object! So make your string an object
and then it should work!

On Dec 31, 2007 8:17 AM, Paddy <paddy3118 at googlemail.com> wrote:

> On Dec 31, 3:42 am, "Peter Pei" <yan... at telus.com> wrote:
> > One bad design about elementtree is that it has different ways parsing a
> > string and a file, even worse they return different objects:
> > 1) When you parse a file, you can simply call parse, which returns a
> > elementtree, on which you can then apply xpath;
> > 2) To parse a string (xml section), you can call XML or fromstring, but
> both
> > return element instead of elementtree. This alone is bad. To make it
> worse,
> > you have to create an elementtree from this element before you can
> utilize
> > xpath.
>
> I haven't tried this, but you should be able to wrap your text string
> so that it looks like a file using the stringio module and pass that
> to elementtree:
>
> http://blog.doughellmann.com/2007/04/pymotw-stringio-and-cstringio.html
>
> - Paddy.
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
http://search.goldwatches.com/?Search=Movado+Watches
http://www.jewelerslounge.com
http://www.goldwatches.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20071231/ab211c5a/attachment.html>


More information about the Python-list mailing list