The XML | Insert | XInclude command is available in Grid View only, and enables you to insert a new XInclude element before the selected item. If the current selection is an attribute, the XInclude element is inserted after the attribute and before the first child element of the attribute's parent element. Selecting this command pops up the XInclude dialog (screenshot below).
The XML file to be included is entered in the href text box (alternatively, you can browse for the file by clicking the Browse (...) button to the right of the text box). The filename will be entered in the XML document as the value of the href attribute. The parse, xpointer, and encoding attributes of the XInclude element (xi:include), and the fallback child element of xi:include can also be inserted via the dialog. Do this by first checking the appropriate check box and then selecting/entering the required values. In the case of the fallback element, checking its check box only inserts the empty element. The content of the fallback element must be added subsequently in one of the editing views.
The parse attribute determines whether the included document is to be parsed as XML or text. (XML is the default value and therefore need not be specified.) The xpointer attribute identifies a specific fragment of the document located with the href attribute; it is this fragment that will be included. The encoding attribute specifies the encoding of the included document so that XMLSpy can transcode this document (or the part of it to be included) into the encoding of the including document. The contents of the fallback child element replace the xi:include element if the document to be included cannot be located.
Here is an example of an XML document that uses XInclude to include two XML documents:
<?xml version="1.0" encoding="UTF-16"?>
<AddressBook xsi:schemaLocation="http://www.altova.com/sv/myaddresses AddressBook.xsd"
When this XML document is parsed, it will replace the two XInclude elements with the files specified in the respective href attributes.
When the XML validator of XMLSpy reads an XML document and encounters the include element in the XInclude namespace (hereafter xi:include), it replaces this element (xi:include) with the XML document named in the href attribute of the xi:include element. The document element (root element) of the included XML document (or the element identified by an XPointer) will be included with an attribute of xml:base in order to preserve the base URIs of the included element. If the resulting XML document (containing the included XML document/s or tree fragment/s) must be valid according to a schema, then the document element of the included document (or the top-level element of the tree fragment) must be created with a content model that allows an attribute of xml:base. If, according to the schema, the xml:base attribute is not allowed on this element, then the resulting document will be invalid. How to define an xml:base attribute in an element's content model using XMLSpy's Schema View is described in the xml:Prefixed Attributes section of the Schema View section of the documentation.
XMLSpy supports XPointers in XInclude. The relevant W3C recommendations are the XPointer Framework and XPointer element() Scheme recommendations. The use of an XPointer in an XInclude element enables a specific part of the XML document to be included, instead of the entire XML document. XPointers are used within an XInclude element as follows:
<xi:include href="PersonalAddressBook.xml" xpointer="element(usa)"/>
<xi:include href="BusinessAddressBook.xml" xpointer="element(/1/1)"/>
<xi:include href="BobsAddressBook.xml" xpointer="element(usa/3/1)"/>
<xi:include href="PatsAddressBook.xml" xpointer="element(usa)element(/1/1)"/>
In the element() scheme of XPointer, an NCName or a child sequence directed by integers may be used.
|•||In the first xi:include element listed above, the xpointer attribute uses the element scheme with an NCName of usa. According to the XPointer Framework, this NCName identifies the element that has an ID of usa.|
|•||In the second xi:include listed above, the xpointer attribute with a value of element(/1/1) identifies, in the first step, the first child element of the document root (which, if the document is well-formed, will be its document (or root) element). In the second step, the first child element of the element located in the previous step is located; in our example, this would be the first child element of the document element.|
|•||The xpointer attribute of the third xi:include listed above uses a combination of NCName and child sequence. This XPointer locates the first child element of the third child element of the element having an ID of usa.|
|•||If you are not sure whether your first XPointer will work, you can back it up with a second one as shown in the fourth xi:include listed above: xpointer="element(usa)element(/1/1)". Here, if there is no element with an ID of usa, the back-up XPointer specifies that the first child element of the document element is to be selected. Additional backups are also allowed. Individual XPointers may not be separated, or they may be separated by whitespace: for example, xpointer="element(usa)element(addresses/1) element(/1/1)".|
|Note:||The namespace binding context is not used in the element() scheme because the element() scheme does not support qualified names.|
© 2019 Altova GmbH