[oXygen-user] XML Schema & XInclude ?

George Cristian Bina
Fri Jul 20 05:20:13 CDT 2007

Dear Timothy,

Ok, I created a full working sample starting from your schema fragment. 
Basically we define a "scopes" element that can contain more "scope" 
elements. A "scope" element has mixed content and can contain 
"important" elements.

All the sample files are available also in an archive here

The sample covers both cases, the schema allows also the xi:include 
element (in the case when XInclude processing is disabled and this is 
needed also for content completion) and the content that replaces the 
xi:include (the additional xml:base attribute that appears on the 
included elements).


<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
   <xs:import namespace="http://www.w3.org/2001/XInclude"
   <xs:import namespace="http://www.w3.org/XML/1998/namespace"
   <xs:element name="scopes">
       <xs:sequence maxOccurs="unbounded">
           <xs:element ref="xi:include" minOccurs="0"/>
           <xs:element ref="scope"/>

   <xs:element name="scope">
         <xs:extension base="scopeType">
           <xs:attributeGroup ref="xml:specialAttrs"/>

   <xs:complexType name="scopeType" mixed="true">
     <xs:choice minOccurs="0">
       <xs:element name="important" type="xs:string"/>
     <xs:attribute name="name" type="xs:string" use="required"/>

A sample XML looks like below:

<?xml version="1.0" encoding="UTF-8"?>
<scopes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   <scope name="test"/>
   <include xmlns="http://www.w3.org/2001/XInclude" href="included.xml"/>
   <scope name="another scope"/>

<?xml version="1.0" encoding="UTF-8"?>
<scope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   This is an <important>included</important> scope.

The other schemas are:

<?xml version='1.0'?>
<xs:schema targetNamespace="http://www.w3.org/XML/1998/namespace" 
xmlns:xs="http://www.w3.org/2001/XMLSchema" xml:lang="en">

    See http://www.w3.org/XML/1998/namespace.html and
    http://www.w3.org/TR/REC-xml for information about this namespace.

     This schema document describes the XML namespace, in a form
     suitable for import by other schema documents.

     Note that local names in this namespace are intended to be defined
     only by the World Wide Web Consortium or its subgroups.  The
     following names are currently defined in this namespace and should
     not be used with conflicting semantics by any Working Group,
     specification, or document instance:

     base (as an attribute name): denotes an attribute whose value
          provides a URI to be used as the base for interpreting any
          relative URIs in the scope of the element on which it
          appears; its value is inherited.  This name is reserved
          by virtue of its definition in the XML Base specification.

     id   (as an attribute name): denotes an attribute whose value
          should be interpreted as if declared to be of type ID.
          The xml:id specification is not yet a W3C Recommendation,
          but this attribute is included here to facilitate experimentation
          with the mechanisms it proposes.  Note that it is _not_ included
          in the specialAttrs attribute group.

     lang (as an attribute name): denotes an attribute whose value
          is a language code for the natural language of the content of
          any element; its value is inherited.  This name is reserved
          by virtue of its definition in the XML specification.

     space (as an attribute name): denotes an attribute whose
          value is a keyword indicating what whitespace processing
          discipline is intended for the content of the element; its
          value is inherited.  This name is reserved by virtue of its
          definition in the XML specification.

     Father (in any context at all): denotes Jon Bosak, the chair of
          the original XML Working Group.  This name is reserved by
          the following decision of the W3C XML Plenary and
          XML Coordination groups:

              In appreciation for his vision, leadership and dedication
              the W3C XML Plenary on this 10th day of February, 2000
              reserves for Jon Bosak in perpetuity the XML name

   <xs:documentation>This schema defines attributes and an attribute group
         suitable for use by
         schemas wishing to allow xml:base, xml:lang or xml:space attributes
         on elements they define.

         To enable this, such a schema must import this schema
         for the XML namespace, e.g. as follows:
         &lt;schema . . .>
          . . .
          &lt;import namespace="http://www.w3.org/XML/1998/namespace"

         Subsequently, qualified reference to any of the attributes
         or the group defined below will have the desired effect, e.g.

         &lt;type . . .>
          . . .
          &lt;attributeGroup ref="xml:specialAttrs"/>

          will define a type which will schema-validate an instance
          element with any of those attributes</xs:documentation>

   <xs:documentation>In keeping with the XML Schema WG's standard versioning
    policy, this schema document will persist at
    At the date of issue it can also be found at
    The schema document at that URI may however change in the future,
    in order to remain compatible with the latest version of XML Schema
    itself, or with the XML namespace itself.  In other words, if the XML
    Schema or XML namespaces change, the version of this document at
    http://www.w3.org/2001/xml.xsd will change
    accordingly; the version at
    http://www.w3.org/2005/08/xml.xsd will not change.

  <xs:attribute name="lang">
    <xs:documentation>This attribute MAY be inserted in documents to 
specify the language used in the
     contents and attribute values of any element in an XML document. 
The values are the ISO 2- and
     3-letter codes. An empty string value means the 'un-declaration' of 
xml:lang. See RFC 3066 at
     http://www.ietf.org/rfc/rfc3066.txt and the IANA registry at
     http://www.iana.org/assignments/lang-tag-apps.htm for further 
    <xs:union memberTypes="xs:language">
      <xs:restriction base="xs:string">
       <xs:enumeration value=""/>

  <xs:attribute name="space">
    <xs:documentation>This attribute is attached to an element to signal 
an intention that in that
     element, white space should be preserved by applications. Possible 
values are "default" and
     "preserve". </xs:documentation>
    <xs:restriction base="xs:NCName">
     <xs:enumeration value="default">
       <xs:documentation>Specifies that the whitespaces should not be 
     <xs:enumeration value="preserve">
       <xs:documentation>Specifies that the whitespaces should be 

  <xs:attribute name="base" type="xs:anyURI">
    <xs:documentation>The attribute xml:base may be inserted in XML 
documents to specify a base URI
     other than the base URI of the document or external entity. See 
     for information about this attribute.</xs:documentation>

  <xs:attribute name="id" type="xs:ID">
    <xs:documentation>Defines an ID value without the need of a DTD or 
    See http://www.w3.org/TR/xml-id/ for information about this 

  <xs:attributeGroup name="specialAttrs">
   <xs:attribute ref="xml:base"/>
   <xs:attribute ref="xml:lang"/>
   <xs:attribute ref="xml:space"/>


<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"


     <xs:documentation> Not normative, but may be useful. See the REC
       http://www.w3.org/TR/XInclude for definitive information about
       this namespace. </xs:documentation>
   <xs:element name="include" type="xi:includeType"/>

   <xs:complexType name="includeType" mixed="true">

     <xs:choice minOccurs="0" maxOccurs="unbounded">
       <xs:element ref="xi:fallback"/>
       <xs:any namespace="##other" processContents="lax"/>
       <xs:any namespace="##local" processContents="lax"/>
     <xs:attribute name="href" use="optional" type="xs:anyURI"/>
     <xs:attribute name="parse" use="optional" default="xml"
     <xs:attribute name="xpointer" use="optional" type="xs:string"/>
     <xs:attribute name="encoding" use="optional" type="xs:string"/>
     <xs:attribute name="accept" use="optional" type="xs:string"/>
     <xs:attribute name="accept-language" use="optional" type="xs:string"/>
     <xs:anyAttribute namespace="##other" processContents="lax"/>

   <xs:simpleType name="parseType">

     <xs:restriction base="xs:token">
       <xs:enumeration value="xml"/>
       <xs:enumeration value="text"/>
   <xs:element name="fallback" type="xi:fallbackType"/>

   <xs:complexType name="fallbackType" mixed="true">

     <xs:choice minOccurs="0" maxOccurs="unbounded">
       <xs:element ref="xi:include"/>
       <xs:any namespace="##other" processContents="lax"/>
       <xs:any namespace="##local" processContents="lax"/>
     <xs:anyAttribute namespace="##other" processContents="lax"/>

Best Regards,
George Cristian Bina - http://aboutxml.blogspot.com/
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger

Timothy Reaves wrote:
> On Tue, July 17, 2007 16:13, George Cristian Bina wrote:
>> Dear Timothy,
>> oXygen has an option "Enable XInclude processing" that I believe is
>> enabled by default. When that is enables the validation against XML Schema
>> is performed after XInclude processing, that means the XML Schema should
>> not care about defining the xi:include element but it should take into
>> account that the included fragment will have an xml:base attribute
>> pointing to the location it was included from and probably also an
>> xml:lang. So for
>> instance if you want to have scope elements inside scopes and you plan to
>> include scope elements from other documents using XInclude then you should
>> define xml:base (and xml:lang) to be allowed in the scope element.
>> When the XInclude processing is not enabled then oXygen will validate
>> the document as it is against the specified XML Schema. In that case you
>> need to refer to the xi:include element inside the schema, as in your
>> sample. The problem in your case is the wrong namespace that you used in
>> import, the correct nemespace is http://www.w3.org/2001/XInclude, that is
>> not with 2003.
>> Best Regards,
>> George
>      Do you have a sample document that shows this working correctly?
> _______________________________________________
> oXygen-user mailing list
> http://www.oxygenxml.com/mailman/listinfo/oxygen-user

More information about the oXygen-user mailing list