XInclude

XInclude is a generic mechanism for merging XML documents. The valid values for the attribute 'parse' are 'text' and 'xml'. Like XLink, its special namespace should be declared before it is used. For a working PHP example, see PHP Integration.

Range Inclusion

The following demonstrates range inclusion: the document invoking XInclude, the source document referenced ('source.xml'), and the resulting XML obtained.

<?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>

<?xml version='1.0'?>
<chapter>
  <p>Sentence 1.  Sentence 2.</p>
  <p><i>Sentence 3.  Sentence 4.</i>  Sentence 5.</p>
</chapter>

<?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>

(Courtesy of http://www.w3.org/TR/xinclude/#examples)

Fallback

The following demonstrates fallback. If neither example.txt nor fallback-example.txt is available, the XML obtained is shown below.

<?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>

<?xml version='1.0'?>
<div>
  <a href="mailto:bob@example.org">Report error</a>
</div>

(Courtesy of http://www.w3.org/TR/xinclude/#examples)



Currently, browsers do not support XLink and XPointer in general. However, they support simple XLinks in SVG.