You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Doc/library/xml.etree.elementtree.rst
+89Lines changed: 89 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -640,6 +640,95 @@ Functions
640
640
:class:`Element` instance and a dictionary.
641
641
642
642
643
+
.. _elementtree-xinclude:
644
+
645
+
XInclude support
646
+
----------------
647
+
648
+
This module provides limited support for
649
+
`XInclude directives <https://www.w3.org/TR/xinclude/>`_, via the :mod:`xml.etree.ElementInclude` helper module. This module can be used to insert subtrees and text strings into element trees, based on information in the tree.
650
+
651
+
Example
652
+
^^^^^^^
653
+
654
+
Here's an example that demonstrates use of the XInclude module. To include an XML document in the current document, use the ``{http://www.w3.org/2001/XInclude}include`` element and set the **parse** attribute to ``"xml"``, and use the **href** attribute to specify the document to include.
By default, the **href** attribute is treated as a file name. You can use custom loaders to override this behaviour. Also note that the standard helper does not support XPointer syntax.
664
+
665
+
To process this file, load it as usual, and pass the root element to the :mod:`xml.etree.ElementTree` module:
666
+
667
+
.. code-block:: python
668
+
669
+
from xml.etree import ElementTree, ElementInclude
670
+
671
+
tree = ElementTree.parse("document.xml")
672
+
root = tree.getroot()
673
+
674
+
ElementInclude.include(root)
675
+
676
+
The ElementInclude module replaces the ``{http://www.w3.org/2001/XInclude}include`` element with the root element from the **source.xml** document. The result might look something like this:
0 commit comments