xml.etree.ElementTree --- The ElementTree XML API — Example

Here's an example that demonstrates use of the XInclude module. To include an XML document in the current document, use the { element and set the parse attribute to "xml", and use the href attribute to specify the document to include.

Bounded code example (external data; do not execute automatically):
```xml
<?xml version="1.0"?>
<document xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include href="source.xml" parse="xml" />
</document>
```

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.

To process this file, load it as usual, and pass the root element to the !xml.etree.ElementTree module

Bounded code example (external data; do not execute automatically):
```python
from xml.etree import ElementTree, ElementInclude

tree = ElementTree.parse("document.xml")
root = tree.getroot()

ElementInclude.include(root)
```

The ElementInclude module replaces the { element with the root element from the source.xml document. The result might look something like this

Bounded code example (external data; do not execute automatically):
```xml
<document xmlns:xi="http://www.w3.org/2001/XInclude">
This is a paragraph.
</document>
```

If the parse attribute is omitted, it defaults to "xml". The href attribute is required.

To include a text document, use the { element, and set the parse attribute to "text"

Bounded code example (external data; do not execute automatically):
```xml
<?xml version="1.0"?>
<document xmlns:xi="http://www.w3.org/2001/XInclude">
Copyright (c) <xi:include href="year.txt" parse="text" />.
</document>
```

The result might look something like

Bounded code example (external data; do not execute automatically):
```xml
<document xmlns:xi="http://www.w3.org/2001/XInclude">
Copyright (c) 2003.
</document>
```