Re: [lxml-dev] Handling processing instructions

On Wed, Oct 28, 2009 at 4:21 AM, Emanuele D'Arrigo <manu3d@gmail.com> wrote:
Evidently I mis-typed or mis-read the first time I tried the ElementTree way of getting a PI that precedes the root element. The obvious ElementTree way does indeed work. My mistake.
And would I be correct in saying one would still need to iterate "upward" to find the very first processing instruction?
I guess I think of .getprevious() and the preceding-sibling XPath axis as horizontal rather than vertical, so I would say that you need to recur or iterate "backwards" to get all nodes preceding the root element.
Chuck

2009/10/28 Chuck Bearden <cfbearden@gmail.com>
Yes, I think we're thinking the same thing. I was thinking "upward" because of the top-bottom orientation of the source code, but "backward" is indeed reasonable in the context of siblings in the tree.. =) Thank you! Now I just hope somebody (Stephan?) will be able to answer question number 2, how to delete a processing instruction from the tree!! Manu

Stefan, I don't know if you missed this thread: is it possible to remove a processing instruction that is a preceding sibling of the root node of an ElementTree? Somehow I can access it via tree.getroot().getprevious() or tree.getroot().itersiblings(preceding=True).next() but I cannot find a way to delete it. A test case to cut&paste: from lxml import etree from StringIO import StringIO tree = etree.parse(StringIO("<?aProcInstrToBeDeleted?><aRoot />")) Thank you! Manu

2009/11/7 Stefan Behnel <stefan_ml@behnel.de>
Done: https://bugs.launchpad.net/lxml/+bug/479613 Manu

2009/10/28 Chuck Bearden <cfbearden@gmail.com>
Yes, I think we're thinking the same thing. I was thinking "upward" because of the top-bottom orientation of the source code, but "backward" is indeed reasonable in the context of siblings in the tree.. =) Thank you! Now I just hope somebody (Stephan?) will be able to answer question number 2, how to delete a processing instruction from the tree!! Manu

Stefan, I don't know if you missed this thread: is it possible to remove a processing instruction that is a preceding sibling of the root node of an ElementTree? Somehow I can access it via tree.getroot().getprevious() or tree.getroot().itersiblings(preceding=True).next() but I cannot find a way to delete it. A test case to cut&paste: from lxml import etree from StringIO import StringIO tree = etree.parse(StringIO("<?aProcInstrToBeDeleted?><aRoot />")) Thank you! Manu

2009/11/7 Stefan Behnel <stefan_ml@behnel.de>
Done: https://bugs.launchpad.net/lxml/+bug/479613 Manu
participants (3)
-
Chuck Bearden
-
Emanuele D'Arrigo
-
Stefan Behnel