File Inclusion
With file inclusion, it is possible to include files and XML elements
for specific parts of the douidefinition.xml
.
To import from other files, the following format is used:
Both parameters file and xpath are optional, but at least one of the two must be present.
Definition of the parameters:
- file
- Indicates which file will be included. If it is null (or empty), the file to be included will be the current file. This parameter is relative to the current file or absolute if it starts with "/".
- xpath
- Indicates the Xpath to be used for searching for the node to be included. If it is null (or empty), the entire file will be included. If more than one node satisfies the search, the first node that satisfies the search will be used. It is important to note that the node found (if any) will be included containing its own text.
- omitParent
-
Indicates whether the root element of the inclusion should be omitted or not. If it is
(value
true
), the root element of the inclusion will be omitted and only the child nodes will be included. Otherwise (valuefalse
), it will be included as well.
If thexpath
parameter has been defined, the root element of the inclusion is the first element that satisfies the given xpath. If thexpath
parameter has not been defined, the root element of the inclusion is the document element.
The default value, if not defined, isfalse
.
This parameter is especially useful when you want to include the child nodes of a certain node and add other sibling nodes.
Below are some usage examples:
Example 1
In this example, the complete content of a file will be included.
File to be included:
Include code used:
Result of the inclusion:
Example 2
In this example, a node whose xpath used corresponds to only one node will be included.
File to be included:
Include code used:
Result of the inclusion:
Example 3
In this example, a node whose xpath used corresponds to more than one node will be included.
File to be included:
Include code used:
Result of the inclusion:
In this case, both "child" nodes satisfy the search, however only the first node will be included.
Example 4
In this example, a node present in the file itself will be included.
Original file:
Result of the inclusion:
Example 5
In this example, a node containing an #include will be included, which is not supported.
File to be included:
In this case, an error will be displayed, as when attempting to include the element <source id="s3"> a second <!-- #include(...) --> is detected, which is not allowed.
Example 6
In this example, a node will be included omitting the root node.
Original file:
Result of the inclusion: