XML technologies / XML / XML in a Nutshell / XInclude / Including text files
(Excerpt from "XML in a Nutshell" by Elliotte Rusty Harold & W. Scott Means)
By default, the XInclude processor assumes that a document referenced by an href attribute is well-formed XML. It is parsed, and its content replaces the xi:include element in the including document. When assembling large documents, however, including unparsed text can also be useful. For example, the program and XML examples in this book could be included directly as source code. If you give a xi:include element the parse attribute with value text, the document is loaded as plain text without parsing. For example, this element includes the code example A document that loads two other documents with XInclude from the page The include element as plain text, without parsing it:
<xi:include href="http://cafeconleche.org/books/xian3/examples/12/12-1.xml" parse="text"/>When parse="text" is specified, the referenced document need not be well-formed or even XML. It may be C source code, an email, a traditional HTML document, or almost anything else. The only restriction is that it must not contain illegal characters such as ASCII NUL or an unmatched half of a surrogate pair.
XInclude processors use available protocol metadata such as HTTP headers to determine the referenced document’s encoding so they can convert it to Unicode before inclusion. If external metadata is unavailable but the MIME media type is text/xml, application/xml or any other type ending in +xml, the processor looks for standard signatures such as byte-order marks or XML declarations to infer the encoding. If these mechanisms are insufficient, the document’s author can give the xi:include element the encoding attribute indicating the document’s expected encoding. For example, this element tries Latin-1 when loading the code example mentioned above:
<xi:include href="http://cafeconleche.org/books/xian3/examples/12/12-1.xml" encoding="ISO-8859-1" parse="text"/>If all else fails, the processor assumes that the document uses UTF-8. Any byte sequence undefined in the document’s encoding—or what the XInclude processor believes that encoding to be—causes a fatal error.
The attribute parse may also have the value xml. This indicates that the referenced document should be parsed. Since it is the default, most authors do not bother specifying parse="xml". Any other value is a fatal error.
Copyright © 2005 O'Reilly Verlag GmbH & Co. KG
You may print the online version for your private use.
Otherwise, this chapter from the book "XML in a Nutshell" is subject to the same conditions as the printed edition: the work and all its parts are protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
O’Reilly Verlag GmbH & Co. KG, Balthasarstraße 81, 50670 Köln, kommentar(at)oreilly.de
back to top