Re: Problem inserting an element where I want it using lxml

2011-01-05 Thread Alan Meyer
On 01/05/2011 01:16 AM, Josh English wrote: Here's a trimmed down version of how I did this (using ElementTree standalone, but the API should be the same) This is from a class definition and the _elem attribute is a link to an ElementTree.Element object. ... def _add_elem(self, tagName, t

Re: Problem inserting an element where I want it using lxml

2011-01-05 Thread Alan Meyer
On 01/05/2011 02:47 AM, Stefan Behnel wrote: ... Looks trivial to me. ;) ... ".iter()" gives you a recursive iterator that will also yield the "something" Element in your case, thus the incorrect counting. You only want the children, so you should iterate over the Element itself. Thanks Stepha

Re: Problem inserting an element where I want it using lxml

2011-01-04 Thread Stefan Behnel
Alan Meyer, 05.01.2011 06:57: I'm having some trouble inserting elements where I want them using the lxml ElementTree (Python 2.6). I presume I'm making some wrong assumptions about how lxml works and I'm hoping someone can clue me in. I want to process an xml document as follows: For every occ

Re: Problem inserting an element where I want it using lxml

2011-01-04 Thread Josh English
Oh, and I usually use a separate function to indent my xml for readability when I need to actually look at the xml. It's easier than trying to change the element in situ and make it look nice. Josh -- http://mail.python.org/mailman/listinfo/python-list

Re: Problem inserting an element where I want it using lxml

2011-01-04 Thread Josh English
Here's a trimmed down version of how I did this (using ElementTree standalone, but the API should be the same) This is from a class definition and the _elem attribute is a link to an ElementTree.Element object. ... def _add_elem(self, tagName, text, attrib ={}): """_add_elem(tagName,

Problem inserting an element where I want it using lxml

2011-01-04 Thread Alan Meyer
I'm having some trouble inserting elements where I want them using the lxml ElementTree (Python 2.6). I presume I'm making some wrong assumptions about how lxml works and I'm hoping someone can clue me in. I want to process an xml document as follows: For every occurrence of a particular elemen