XML technologies / XML / XML in a Nutshell / XInclude / XPointers

(Excerpt from "XML in a Nutshell" by Elliotte Rusty Harold & W. Scott Means)

For architectural reasons, URLs in the href attributes of XIncludes must not have fragment identifiers. This is a fatal error: the XInclude processor simply gives up and stops. Instead, each xi:include element can have an xpointer attribute. This attribute contains an XPointer, indicating which part of the document referenced by the href attribute should be included. For example, this xi:include element loads the day’s headlines from Cafe con Leche, enclosed by a today element in the namespace "http://www.w3.org/1999/xhtml", but not the rest of the page:

<xi:include href="http://www.cafeconleche.org/" xpointer="xmlns(pre=http://www.w3.org/1999/xhtml) xpointer(//pre:today)"/>

You could also use the element( ) scheme:

<xi:include href="http://www.cafeconleche.org/" xpointer="element(/1/2/4/1/1/4)"/>

If the href attribute is absent, the XPointer refers to the current document.

XInclude processors need not support every XPointer scheme. In particular, they are not required to support the xpointer( ) or xmlns( ) schemes, although some processors, such as libxml2, provide this support. All processors must support the element( ) scheme and shorthand XPointers. In practice, some implementations, particularly those based on streaming APIs such as SAX, provide no XPointer support at all.

A syntax error in the XPointer is a resource error that causes the xi:fallback child element to be processed, if present. This is not necessarily a fatal error.

Since XPointers apply only to XML documents, they can be used only when parse="xml" is specified. It is a fatal error for an xi:include element to have both an xpointer and a parse="text" attribute.

  

 

 

 

back to top