Adding attribute for root-type in derived schema
This should cover W3C XML Schema, Relax NG and DTD related problems.
-
- Posts: 280
- Joined: Thu Nov 28, 2013 9:32 am
- Location: Hamburg/Germany
- Contact:
Adding attribute for root-type in derived schema
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:
This works fine so far but I get following warning:
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
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>
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.
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
-
- Posts: 9428
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Adding attribute for root-type in derived schema
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
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
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 404
- 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:
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.
I hope this helps.
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>
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>
Radu Pisoi
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
-
- Posts: 280
- Joined: Thu Nov 28, 2013 9:32 am
- Location: Hamburg/Germany
- Contact:
Re: Adding attribute for root-type in derived schema
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
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
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service