Adding attribute for root-type in derived schema

This should cover W3C XML Schema, Relax NG and DTD related problems.
Patrik
Posts: 280
Joined: Thu Nov 28, 2013 9:32 am
Location: Hamburg/Germany
Contact:

Adding attribute for root-type in derived schema

Post by Patrik »

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: 9048
Joined: Fri Jul 09, 2004 5:18 pm

Re: Adding attribute for root-type in derived schema

Post by Radu »

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: 403
Joined: Thu Aug 21, 2003 11:36 am
Location: Craiova
Contact:

Re: Adding attribute for root-type in derived schema

Post by radu_pisoi »

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: 280
Joined: Thu Nov 28, 2013 9:32 am
Location: Hamburg/Germany
Contact:

Re: Adding attribute for root-type in derived schema

Post by Patrik »

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
Post Reply