XInclude
XInclude is a very simple “import” facility for XML
documents. With the XInclude directive, you can easily include one XML
document in another either as XML or as plain (and escaped) text. This
means that you can break down your documents into as many files as you see
fit and reference the pieces in a simple, standard way. We should note
that it is also possible to do this in another way, using XML entity
declarations, but they are fraught with problems. XInclude is simpler and
does what its name implies, including the specified document at the
current location; you just have to declare the proper namespace for the
new <include> element.
Here is an example:
<Bookxmlns:xi="http://www.w3.org/2001/XInclude"><Title>LearningJava</Title><xi:includehref="chapter1.xml"/><xi:includehref="chapter2.xml"/><xi:includehref="chapter3.xml"/>...</Book>
We’ve used the namespace identifier xi to qualify the <include> elements that we use to import
the chapters of our book. By default, the file is imported as XML content,
which means that the parser incorporates the included document as part of
our document. The resulting DOM or SAX view will show the merged documents
as one. Alternatively, we can use the parse attribute to
specify that we want the target included as text only. In this case, the
text is automatically escaped for us like a CDATA section. For example, we
could use it to include an XML example in our book without danger of it
being intepreted as part of our file: