[lxml-dev] PI attribute access
Stefan Behnel
stefan_ml at behnel.de
Thu Feb 8 19:00:07 CET 2007
Hi,
Lee Brown wrote:
> I presume from the previous mailing list traffic and some code introspection
> that this is the "right" way to handle xml-stylesheet PIs:
>
> xml_tree = etree.parse(xml_data)
> xsl_pi = xml_tree.getroot().getprevious()
> xsl_tree = xsl_pi.parseXSL()
> transformer = etree.XSLT(xsl_tree)
> result = transformer(xml_tree)
>
> There's one suprise, though: I had thought from the mailing list discussion
> that 'href' attribute would be accessible by the get() and set() methods - but
> it isn't; everything past the tag is kept simply as text.
... which is basically how PIs look like according to the XML spec.
I just added a fake implementation for get() that parses the text for
attribute-like text sequences. For simplicity, however, the set() method only
supports setting the href 'attribute' for now.
Have fun,
Stefan
More information about the lxml-dev
mailing list