XML Processing Modules
xml.etree.ElementInclude
Expands XInclude directives in ElementTree documents. Inclusion can read external resources through a loader, so never allow uncontrolled include paths from untrusted documents. A custom loader can resolve only approved resources. The example uses a fixed in-memory text mapping.
Formal Syntax & Structure
python syntaxpython
import xml.etree.ElementIncludeReturn Value
module
Module namespace available through import; import is a statement, not a value-returning expression.
Working Example
Example Snippetpython
from xml.etree import ElementTree as ET, ElementIncluderoot = ET.fromstring('<r xmlns:xi="http://www.w3.org/2001/XInclude"><xi:include href="note" parse="text"/></r>')ElementInclude.include(root, loader=lambda href, parse, encoding=None: {"note": "tea"}[href])print(root.text)