Adding attribute for root-type in derived schema

This should cover W3C XML Schema, Relax NG and DTD related problems.
Patrik
Posts: 227
Location: Hamburg/Germany

Adding attribute for root-type in derived schema

Mon Dec 02, 2013 3:52 pm

Hi,

I have two document types:
1. for generic documents (a specialization of dita)
2. for specifications

In the first one for instance the topic and section elements (and several others) have the attribute audience. I realizes this by deriving these types from a common base type containing these attributes. Since the complete xsd is quite large I've split it into several files.

Now for my specifications I want to extend the xsd for generic documents. One part of this is adding a diff attribute for every element that has the audience attribute. I'm doing this by importing the xsd with xs:redefine:

Code: Select all

<xs:redefine schemaLocation="genericbook.xsd">
   <xs:complexType name="BaseType">
      <xs:complexContent>
         <xs:extension base="BaseType">
            <xs:attribute ref="diff"/>
         </xs:extension>
      </xs:complexContent>
   </xs:complexType>
</xs:redefine>


This works fine so far but I get following warning:

Code: Select all

Saxon-EE 9.5.0.2
The redefined complex type was found, but not in the schema document referenced by the schemaLocation attribute of the containing <xs:redefine> element. This is not allowed by the XSD specification. However, Saxon does not currently enforce this rule.


Now I'm wondering how else I can achieve the desired extension of the base type!? AttributeGroups would work as well but I found no way to extend these. Putting the complete base schema in one file works but it's no real option since the file gets too large to maintain confortably.

If there is no other way to do this in a xsd conform way: Is it at least possible to suppress the saxon warning?

Thanks for any ideas.

Patrik
Radu
Posts: 5505

Re: Adding attribute for root-type in derived schema

Tue Dec 03, 2013 11:15 am

Hi Patrik,

The XML Schema specs related to redefines is here:

http://www.w3.org/TR/xmlschema11-1/#element-redefine

In my opinion constraint 4.2 from there states that the redefined schema contains all its includes already expanded and as part of it.

I actually added an issue on the Xerces bugs list a while ago with this precise situation:

https://issues.apache.org/jira/browse/XERCESJ-1584

Basically Xerces and Saxon behave differently when validating this situation. In this case I prefer Xerces's approach better because it is more flexible, the includes of the redefined element are actually processed before the redefine occurs.
Saxon's warning cannot be suppressed.

I will discuss this also with my colleagues, I do not see right now a way in which you can redefine the base type in an XML Schema 1.0 and add one more attribute to it other than using redefines.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
radu_pisoi
Posts: 324
Location: Craiova

Re: Adding attribute for root-type in derived schema

Tue Dec 03, 2013 3:54 pm

Hi Patrik,

From the initial post I understand that you want to redefine an attribute group by adding one or more attributes. The attribute group that you want to redefine is available in a schema located on the third or higher level on the schema hierarchy.

A sample configuration may looks like:
main.xsd -include-> second.xsd -include-> attrGroupSchema.xsd

The problem reported by the Saxon is that the component you want to extend should be declared in the schema that you redefine. To resolve this, you have to include the schema that is currently redefined. Also you have to add a redefine directive to the schema that declares the attribute group. The redefine directive allows you to extend the attribute group as fallows:

Code: Select all

<!-- Include the schema that is currently redefined. In you case 'genericbook.xsd' -->
<xs:include schemaLocation="second.xsd">
<!-- Redefine the schema that declares the attribute group.-->
<xs:redefine schemaLocation="attrGroupSchema.xsd">
  <!-- Extends the attribute group by adding the diff attribute -->
  <xs:attributeGroup name="attributeGroupToExtend">           
    <xs:attributeGroup ref="attributeGroupToExtend"/>           
    <xs:attribute ref="diff"/>   
  </xs:attributeGroup>
</xs:redefine>


Another solution is to use the override feature that is available in XML Schema 1.1. The <override> element replaces the XML Schema 1.0 <redefine> element, which has been deprecated. The <override> element is used to replace the contents of a globally declared item in another schema.

In this case you should replace the redefine directive with override. Inside the override element you should redeclare the attribute group. If your case is to extend the attribute group by adding an attribute, you have to copy the original attribute group declaration and add the new attributes at the end.

Code: Select all

<xs:override schemaLocation="second.xsd">
  <xs:attributeGroup name="attributeGroupToExtend">
    <!-- Declarations or references to the ather attributes or attributes groups -->
    <xs:attribute ref="diff"/>   
  </xs:attributeGroup>
</xs:override>


I hope this helps.
Radu Pisoi
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Patrik
Posts: 227
Location: Hamburg/Germany

Re: Adding attribute for root-type in derived schema

Wed Dec 04, 2013 8:53 am

Thanks alot to both of you.

Since I want to avoid having to copy (and maintain) the original attributes in the new definition I sticked to redefine according your desctiption and it works - without warning! :-)

(Still good to know about the override element - will surely use it soon.)

Regards,

Patrik

Return to “XML Schemas”

Who is online

Users browsing this forum: No registered users and 1 guest