Example 1 | Elements and attributes:
XInclude standard defines two elements - include and fallback, and six attributes
-
href,
parse.
xpointer.
encoding,
accept, and
accept-language.
The elements are from the namespace
http://www.w3.org/2001/XInclude.
|
---|
Example 2 | Attribute href:
The href attribute of the include element tells the processor which document fragment(s) should be included. |
---|
Example 3 | Attribute parse = xml:
If the parse attribute of the
include element is set to 'xml',
the included file (or its fragment)
will be parsed (and included) as XML.
This will give exactly the same result as in previous
example.
|
---|
Example 4 | Attribute parse = text:
If the parse attribute of the include element is set to 'text', the included file (or its fragments) will be included as sequence of characters. |
---|
Example 5 | Element fallback:
Element fallback tells the processor, what to do in case of resource error (a failure of an attempt to fetch a resource from a URL) - non-existent file, bad connection, etc. When this happens, include
element is replaced with the contents of the fallback element. The fallback must be a child of the include element. It can contain anything. |
---|
Example 6 | Element fallback can contain also include element:
Element fallback can contain anything, so also
the include element. |
---|
Example 7 | Attribute encoding and parse="text":
If the parse attribute of the
include element
is set to 'text',
you may sometimes need to specify the encoding
of the included document.
|
---|
Example 8 | Attribute encoding and parse="xml":
In this case, the attribute encoding has no effect.
XML files carry their encoding with them. |
---|
Example 9 | Including only a part of the file (parse = xml) -
attribute xpointer:
We can also include only a fragment of the file,
using XPointer.
|
---|
Example 10 | Recursion is an error:
You must not include the document fragment(s) in a way, which would lead to a recursion. |
---|
Example 11 | When parse=text, there will be no recursion:
If parse is set to "text", there is
no problem with recursive inclusions.
|
---|
Example 12 | Including only a part of the file (parse = xml):
There will be no recursion - we just fetch the
element /b/p[1] from file b.xml.
|
---|
Example 13 | Missing href attribute:
If the attribute href is missing, it is equivalent
to: href="". In this case,
xpointer attribute must be present.
Warning: this may be treated as resource error.
|
---|
Example 14 | Including attribute or namespace is an error:
You can't include attribute or namespace node.
|
---|