Re: replacing xml elements with other elements using lxml

2007-08-30 Thread Stefan Behnel
Ultrus wrote: > Ah! I figured it out. I forgot that the tree is treated like a list. > The solution was to replace the element with the first > child, then use Python's insert(i,x) function to insert elements after > the first one. You could also use slicing, something like: parent[2:3] = c

Re: replacing xml elements with other elements using lxml

2007-08-29 Thread Ultrus
Ah! I figured it out. I forgot that the tree is treated like a list. The solution was to replace the element with the first child, then use Python's insert(i,x) function to insert elements after the first one. lxml rocks! -- http://mail.python.org/mailman/listinfo/python-list

Re: replacing xml elements with other elements using lxml

2007-08-29 Thread Ultrus
Stefan, I'm honored by your response. You are correct about the bad xml. I attempted to shorten the xml for this example as there are other tags unrelated to this issue in the mix. Based on your feedback, I was able to make following fully functional code using some different techniques: from lxm

Re: replacing xml elements with other elements using lxml

2007-08-29 Thread Stefan Behnel
Ultrus wrote: > I'm attempting to generate a random story using xml as the document, > and lxml as the parser. I want the document to be simplified before > processing it further, and am very close to accomplishing my goal. > Below is what I have so far. Any ideas on how to move forward? > > The g

replacing xml elements with other elements using lxml

2007-08-29 Thread Ultrus
Hello, I'm attempting to generate a random story using xml as the document, and lxml as the parser. I want the document to be simplified before processing it further, and am very close to accomplishing my goal. Below is what I have so far. Any ideas on how to move forward? The goal: read and edit