The following XML document contains an xi:include
element
which points to an external document. Assume the base URI of this document is
http://www.example.org/document.xml
.
<?xml version='1.0'?> <document xmlns:xi="http://www.w3.org/2001/XInclude"> <p>120 Mz is adequate for an average home user.</p> <xi:include href="disclaimer.xml"/> </document>
disclaimer.xml contains:
<?xml version='1.0'?> <disclaimer> <p>The opinions represented herein represent those of the individual and should not be interpreted as official policy endorsed by this organization.</p> </disclaimer>
The infoset resulting from resolving inclusions on this document is the same (except for the include history and language properties) as that of the following document:
<?xml version='1.0'?> <document xmlns:xi="http://www.w3.org/2001/XInclude"> <p>120 Mz is adequate for an average home user.</p> <disclaimer xml:base="http://www.example.org/disclaimer.xml"> <p>The opinions represented herein represent those of the individual and should not be interpreted as official policy endorsed by this organization.</p> </disclaimer> </document>
The following XML document includes a "working example" into a document.
<?xml version='1.0'?> <document xmlns:xi="http://www.w3.org/2001/XInclude"> <p>This document has been accessed <xi:include href="count.txt" parse="text"/> times.</p> </document>
where count.txt contains:
324387
The infoset resulting from resolving inclusions on this document is the same (except for the include history and language properties) as that of the following document:
<?xml version='1.0'?> <document xmlns:xi="http://www.w3.org/2001/XInclude"> <p>This document has been accessed 324387 times.</p> </document>
The following XML document includes a "working example" into a document.
<?xml version='1.0'?> <document xmlns:xi="http://www.w3.org/2001/XInclude"> <p>The following is the source of the "data.xml" resource:</p> <example><xi:include href="data.xml" parse="text"/></example> </document>
data.xml contains:
<?xml version='1.0'?> <data> <item><![CDATA[Brooks & Shields]]></item> </data>
The infoset resulting from resolving inclusions on this document is the same (except for the include history and language properties) as that of the following document:
<?xml version='1.0'?> <document xmlns:xi="http://www.w3.org/2001/XInclude"> <p>The following is the source of the "data.xml" resource:</p> <example><?xml version='1.0'?> <data> <item><![CDATA[Brooks & Shields]]></item> </data></example> </document>
The following illustrates the results of including fragments of
another XML document. Assume the base URI of the document is
http://www.example.com/JoeSmithQuote.xml
.
<?xml version='1.0'?> <price-quote xmlns:xi="http://www.w3.org/2001/XInclude"> <prepared-for>Joe Smith</prepared-for> <good-through>20040930</good-through> <xi:include href="price-list.xml" xpointer="w002-description"/> <volume>40</volume> <xi:include href="price-list.xml" xpointer="element(w002-prices/2)"/> </price-quote>
price-list.xml references a DTD which declares the id
attributes as type ID
, and contains:
<?xml version='1.0'?> <!DOCTYPE price-list SYSTEM "price-list.dtd"> <price-list xml:lang="en-us"> <item id="w001"> <description id="w001-description"> <p>Normal Widget</p> </description> <prices id="w001-prices"> <price currency="USD" volume="1+">39.95</price> <price currency="USD" volume="10+">34.95</price> <price currency="USD" volume="100+">29.95</price> </prices> </item> <item id="w002"> <description id="w002-description"> <p>Super-sized widget with bells <i>and</i> whistles.</p> </description> <prices id="w002-prices"> <price currency="USD" volume="1+">59.95</price> <price currency="USD" volume="10+">54.95</price> <price currency="USD" volume="100+">49.95</price> </prices> </item> </price-list>
The infoset resulting from resolving inclusions on this document is the same (except for the include history and language properties) as that of the following document:
<?xml version='1.0'?> <price-quote xmlns:xi="http://www.w3.org/2001/XInclude"> <prepared-for>Joe Smith</prepared-for> <good-through>20040930</good-through> <description id="w002-description" xml:lang="en-us" xml:base="http://www.example.com/price-list.xml"> <p>Super-sized widget with bells <i>and</i> whistles.</p> </description> <volume>40</volume> <price currency="USD" volume="10+" xml:lang="en-us" xml:base="http://www.example.com/price-list.xml">54.95</price> </price-quote>
The following illustrates the results of including a range
specified by an XPointer. Assume the base URI of the document
is http://www.example.com/document.xml
.
<?xml version='1.0'?> <document> <p>The relevant excerpt is:</p> <quotation> <include xmlns="http://www.w3.org/2001/XInclude" href="source.xml" xpointer="xpointer(string-range(chapter/p[1],'Sentence 2')/ range-to(string-range(/chapter/p[2]/i,'3.',1,2)))"/> </quotation> </document>
source.xml contains:
<chapter> <p>Sentence 1. Sentence 2.</p> <p><i>Sentence 3. Sentence 4.</i> Sentence 5.</p> </chapter>
The infoset resulting from resolving inclusions on this document is the same (except for the include history and language properties) as that of the following document:
<?xml version='1.0'?> <document> <p>The relevant excerpt is:</p> <quotation> <p xml:base="http://www.example.com/source.xml">Sentence 2.</p> <p xml:base="http://www.example.com/source.xml"><i>Sentence 3.</i></p> </quotation> </document>
The following XML document relies on the fallback mechanism to
succeed in the event that the resources example.txt
and
fallback-example.txt
are not available..
<?xml version='1.0'?> <div> <xi:include href="example.txt" parse="text" xmlns:xi="http://www.w3.org/2001/XInclude"> <xi:fallback><xi:include href="fallback-example.txt" parse="text"> <xi:fallback><a href="mailto:bob@example.org">Report error</a></xi:fallback> </xi:include></xi:fallback> </xi:include> </div>
If neither example.txt
nor fallback-example.txt
are available, the infoset resulting from resolving inclusions on this document
is the same (except for the include history
and language properties)
as that of the following document:
<?xml version='1.0'?> <div> <a href="mailto:bob@example.org">Report error</a> </div>