[lxml-dev] lxml replace() deletes tail

Hi, We have a question about the etree.replace() function. We found that it doesn't preserve the tail text from the replaced node when inserting a new node. Perhaps this is the intended behavior, but, to us, it was unexpected. In the example below, notice how the "tail" text is deleted when the <p> is replaced:
Any ideas or comments? Thanks. Luke Tucker & Chris Abraham

Hi, Chris Abraham wrote:
That *is* the expected behaviour. :) When you replace the element "<p>textin</p>tail" with the element "<div>new</div>" you get "<div>new</div>". Note that the tail is a property of the element, so it would rather be unexpected if the replaced element copied its own tail over to the new element. You can always copy the tail from the original element by hand, in case you need to. Stefan

Hi, Chris Abraham wrote:
That *is* the expected behaviour. :) When you replace the element "<p>textin</p>tail" with the element "<div>new</div>" you get "<div>new</div>". Note that the tail is a property of the element, so it would rather be unexpected if the replaced element copied its own tail over to the new element. You can always copy the tail from the original element by hand, in case you need to. Stefan
participants (2)
-
Chris Abraham
-
Stefan Behnel