<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><head><style>p {margin:0px;padding:0px;} blockquote { border: 0px; margin-top: 0px; margin-bottom: 0px; }</style></head><body style="">
<p><font color="#000000"><font size="2"><font face="Verdana">Hi Stefan,</font></font></font><br></p><p> </p><p><font color="#000000" face="Verdana" size="2"><blockquote type="cite"></blockquote><blockquote type="cite">their own siblings (as you did in your example). I changed the implementation<br>to copy *all* source nodes first, and *then* start replacing them in the<br>target slice. Previously, they were copied over one by one while doing the<br>replacements, so now you're on the safe side here.<br></blockquote></font></p><p> </p><p> </p><p>I can confirm the objectify case works for me now:</p><p> </p><p>>>><br>>>> import lxml.etree<br>>>> import lxml.objectify<br>>>><br>>>> xml = lxml.objectify.XML(<br>... '<a xmlns:py="http://codespeak.net/lxml/objectify/pytype">'<br>... '<b name="b1"><title py:pytype="str">tit</title><text>foo</text></b>'<br>... '<b name="b2"><text>bar</text></b></a>')<br>>>><br>>>> print lxml.etree.tostring(xml, pretty_print=True)<br><a xmlns:py="http://codespeak.net/lxml/objectify/pytype"><br> <b name="b1"><br> <title py:pytype="str">tit</title><br> <text>foo</text><br> </b><br> <b name="b2"><br> <text>bar</text><br> </b><br></a><br> <br>>>><br>>>> foo = xml['b'][0]<br>>>> bar = xml['b'][1]<br>>>> foo['text'] = 'FOO!'<br>>>><br>>>> print lxml.etree.tostring(xml, pretty_print=True)<br><a xmlns:py="http://codespeak.net/lxml/objectify/pytype"><br> <b name="b1"><br> <title py:pytype="str">tit</title><br> <text py:pytype="str">FOO!</text><br> </b><br> <b name="b2"><br> <text>bar</text><br> </b><br></a><br> <br>>>><br>>>> foo = xml['b'][0]<br>>>> bar = xml['b'][1]<br>>>> xml['b'] = [bar, foo]<br>>>><br>>>> print lxml.etree.tostring(xml, pretty_print=True)<br><a xmlns:py="http://codespeak.net/lxml/objectify/pytype"><br> <b name="b2"><br> <text>bar</text><br> </b><br> <b name="b1"><br> <title py:pytype="str">tit</title><br> <text py:pytype="str">FOO!</text><br> </b><br></a> </p><p> <br>>>> print etree.__version__<br>2.0.0-51328 <br></p><p><font color="#000000" face="Verdana" size="2"> </font><font color="#000000" face="Verdana" size="2"></font></p><blockquote type="cite"><font color="#000000" face="Verdana" size="2"><a href="http://service.gmx.net/fm07/g.fcgi/mail/new?CUSTOMERNO=1130295&t=de1814051385.1202304769.5d74dc62&to="></a>although you can still do<br><br> el.a = [el1, el2]<br></font></blockquote><blockquote type="cite"> </blockquote><br><p>>>> l = [1, 2, 3, 4]</p><p>>>> l[2:3] = ["a", "b", "c", "d"]<br>>>> l<br>[1, 2, 'a', 'b', 'c', 'd', 4]<br>>>> root = objectify.Element("root")<br>>>> root.l = [1, 2, 3, 4]<br>>>> root.l[2:3] = ["a", "b", "c", "d"]<br>>>> print objectify.dump(root)<br>root = None [ObjectifiedElement]<br> l = 1 [IntElement]<br> * py:pytype = 'int'<br> l = 2 [IntElement]<br> * py:pytype = 'int'<br> l = 'a' [StringElement]<br> * py:pytype = 'str'<br> l = 4 [IntElement]<br> * py:pytype = 'int'<br> l = 'b' [StringElement]<br> * py:pytype = 'str'<br> l = 'c' [StringElement]<br> * py:pytype = 'str'<br> l = 'd' [StringElement]<br> * py:pytype = 'str'<br>>>> etree.tostring(root, pretty_print=True)<br>'<root xmlns:py="http://codespeak.net/lxml/objectify/pytype" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" py:pytype="TREE">\n <l py:pytype="int">1</l>\n <l py:pytype="int">2</l>\n <l py:pytype="str">a</l>\n <l py:pytype="int">4</l>\n <l py:pytype="str">b</l>\n <l py:pytype="str">c</l>\n <l py:pytype="str">d</l>\n</root>\n'<br>>>> print etree.tostring(root, pretty_print=True)<br><root xmlns:py="http://codespeak.net/lxml/objectify/pytype" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" py:pytype="TREE"><br> <l py:pytype="int">1</l><br> <l py:pytype="int">2</l><br> <l py:pytype="str">a</l><br> <l py:pytype="int">4</l><br> <l py:pytype="str">b</l><br> <l py:pytype="str">c</l><br> <l py:pytype="str">d</l><br></root><br> <br>>>> </p><p> </p><p>So the correct slice gets substituted, but the order is a bit confused.</p><p> </p><blockquote type="cite"><font color="#000000" face="Verdana" size="2">I don't think anyone will really miss the first one, especially as it only<br>worked for one list level anyway.</font></blockquote><p> </p><p>Right. I think the slice assignment stuff is basically corner cases, but it's nice somehow :-)</p><p>But I won't miss the first one for sure.</p><p> </p><p>Cheers,</p><p>Holger </p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><div class="signature"><br /><br /><br />-- <br />GMX FreeMail: 1 GB Postfach, 5 E-Mail-Adressen, 10 Free SMS.<br />Alle Infos und kostenlose Anmeldung: http://www.gmx.net/de/go/freemail</div></body></html>