Fix xml.etree.ElementInclude to include the tail of the current node. Issue #6231
authorFlorent Xicluna <florent.xicluna@gmail.com>
Sun, 8 Aug 2010 23:08:41 +0000 (23:08 +0000)
committerFlorent Xicluna <florent.xicluna@gmail.com>
Sun, 8 Aug 2010 23:08:41 +0000 (23:08 +0000)
Lib/test/test_xml_etree.py
Lib/xml/etree/ElementInclude.py
Misc/NEWS

index 4c9f2e070b3721c72bac3f893c80949f3d4a0eb1..39997cc5ee934de221a51563663520e5354f9f6a 100644 (file)
@@ -1277,6 +1277,14 @@ XINCLUDE["C2.xml"] = """\
 
 XINCLUDE["count.txt"] = "324387"
 
+XINCLUDE["C2b.xml"] = """\
+<?xml version='1.0'?>
+<document xmlns:xi="http://www.w3.org/2001/XInclude">
+  <p>This document has been <em>accessed</em>
+  <xi:include href="count.txt" parse="text"/> times.</p>
+</document>
+"""
+
 XINCLUDE["C3.xml"] = """\
 <?xml version='1.0'?>
 <document xmlns:xi="http://www.w3.org/2001/XInclude">
@@ -1352,6 +1360,16 @@ def xinclude():
       324387 times.</p>
     </document>
 
+    Textual inclusion after sibling element (based on modified XInclude C.2)
+
+    >>> document = xinclude_loader("C2b.xml")
+    >>> ElementInclude.include(document, xinclude_loader)
+    >>> print(serialize(document)) # C2b
+    <document>
+      <p>This document has been <em>accessed</em>
+      324387 times.</p>
+    </document>
+
     Textual inclusion of XML example (XInclude C.3)
 
     >>> document = xinclude_loader("C3.xml")
index dde0a41531c0030a87ae66051440e65ebb8df016..84fd7548b28a0c5f51193caf28bdf045cc1ea3a7 100644 (file)
@@ -125,7 +125,7 @@ def include(elem, loader=None):
                         )
                 if i:
                     node = elem[i-1]
-                    node.tail = (node.tail or "") + text
+                    node.tail = (node.tail or "") + text + (e.tail or "")
                 else:
                     elem.text = (elem.text or "") + text + (e.tail or "")
                 del elem[i]
index c5fe3d81dee6619a72248943da4393632bf46690..46ddfef855c2cfca2e348c51e8aa4750d4cf8388 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -63,6 +63,9 @@ Extensions
 Library
 -------
 
+- Issue #6231: Fix xml.etree.ElementInclude to include the tail of the
+  current node.
+
 - Issue #8047: Fix the xml.etree serializer to return bytes by default.  Use
   ``encoding="unicode"`` to generate a Unicode string.