XInclude - NXML

Nexaweb's XInclude provides a way to dynamically include and reuse XML, XML fragments and text inside of an XML Document as if the included content had been declared inside the original document to begin with. Nexaweb's XInclude is a subset of the w3c.org Version 1 Recommendation (http://www.w3.org/TR/xinclude/).

The following example shows the use of XInclude in an Initial File(index.nxml):

<nxml>
 <rootPane>
     <xi:include xmlns:xi="http://nexaweb.com/xinclude" href="header.xml"/>
     <xi:include xmlns:xi="http://nexaweb.com/xinclude" href="body.xml"/>
 </rootPane>
</nxml> 

 In this example, the user specifies two attributes:

  • xmlns:xi - the namespace for the XInclude instructions. You must use: http://www.nexaweb.com/xinclude
  • href- an http reference to a static file, dynamic server pages, or servlets

Using XInclude is not the same as simply combining all the pages into one file, because of the timing of loading included pages. If a page has <include> elements, those elements are resolved before the initial page is fully loaded and parsed. In the following example:

  1. index.nxml is retrieved, parsed and displayed.
  2. header.xml is requested and then merged into the existing document.
  3. body.xml is requested and then merged into the existing document.
  4. If header.xml or body.xml has more include tags, they will be retrieved after both header.xml and body.xml.

header.xml:

<label text="Welcome to Acme company"/>

body.xml:

<button text="Click for company Information"/> 
<button text="Click for company Products"/>

The resulting in-memory document will be:

<nxml>
 <rootPane>
  <label text="Welcome to Acme company"/>
  <button text="Click for company Information"/>
  <button text="Click for company Products"/>
 </rootPane>
</nxml> 

You can include the following forms of  data:

  • XML fragments (XML without root tags)
  • Well formed XML or text wrapped in a CDATA tag.
  • Non-namespaced UI elements and namespaced Nexaweb page elements such as mco and macro declarations. The namespaced page elements are always run before the non-namespaced elements are included, regardless of their order in the document, just as they are pages not included via xinclude.

Please see the XInclude Reference Guide for more information on XInclude.