John Krukoff | 5 Feb 21:58
Favicon

Re: Get the xml-stylesheet processing instruction

On Fri, 2010-02-05 at 20:02 +0000, Emanuele D'Arrigo wrote:
<snip>

> True, obtaining PIs (and comments) is not exactly intuitive nor
> straightforward (in, fact for head-of-file PIs it's straightbackward!!
> =) ). I guess ideally there could be a list of them available via
> read-only properties on the tree object, i.e.: docTree.PIs and
> docTree.comments.
> 
> Manu

I agree, although my version of ideally would be for the ElementTree class 
to do a better imitation of being a root node, so that something simple 
like this would work for looping over all root level nodes:

>>> from lxml import etree
>>> x = etree.XML( '<!--Comment--><?PI?><root/>' )
>>> t = x.getroottree()
>>> list( t )
[<!--Comment-->, <?PI?>, <Element root at 872f66c>]

Or if ElementTree even supported just getchildren() to retrieve the same
data. Even more ideally ;) it'd support insert/append/replace/remove and
company for editing such root level elements. Oh yeah, and if
xpath( '/' ) returned said extended ElementTree as the root node, as
long as I'm wishing for ponies and unicorns.

I suppose the reason it's hard is because effbot's ElementTree hasn't
ever dealt with the issue of non-element root level contents.

--

-- 
John Krukoff <jkrukoff <at> ltgc.com>
Land Title Guarantee Company

Gmane