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
{{ message }}
Repository navigation
Commit 195dc14
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: Doc/library/xml.etree.elementtree.rst
+89Lines changed: 89 additions & 0 deletions
Display the source diff
Display the rich diff
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:
If the **parse** attribute is omitted, it defaults to "xml". The href attribute is required.
685
+
686
+
To include a text document, use the ``{http://www.w3.org/2001/XInclude}include`` element, and set the **parse** attribute to "text":
0 commit comments