Problems with restriction
Having trouble installing Oxygen? Got a bug to report? Post it all here.
Problems with restriction
Hi,
Looks like there are problems with restriction.
Here is an example xsd:
Basically I have an enum tPredefinedEnum allowing CBR and DIS as values. Then, I have two types, tSuper and its sub-type tSub. tSuper has an attribute dummy of that tPredefinedEnum type.
tSub is a restriction of tSuper, by fixing the value of the dummy attribute to DIS.
This seems perfectly valid to me and other validators do accept this. oXygen does however complain:
- [ OxygenBugs.xsd] E derivation-ok-restriction.2.1.2: Error for type 'tSub'. An attribute use in this type has a type which is not validly derived from the type of the matching attribute use in the base type. (33:18)
- [ OxygenBugs.xsd] E cos-particle-restrict.2: Forbidden particle restriction: 'any:choice,sequence,all,elt'. (30:30)
- [ OxygenBugs.xsd] E derivation-ok-restriction.5.3.2: Error for type 'tSub'. The particle of the type is not a valid restriction of the particle of the base. (30:30)
Are restrictions not supported or am I doing something wrong?
Thanks!
Chris
Looks like there are problems with restriction.
Here is an example xsd:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSPY v5 rel. 4 U (http://www.xmlspy.com) by Christian Frei (ABB Schweiz, Corp. Research) -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="super" type="tSuper">
<xs:annotation>
<xs:documentation>Comment describing your root element</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="sub" type="tSub"/>
<xs:simpleType name="tPredefinedEnum">
<xs:restriction base="xs:Name">
<xs:enumeration value="CBR"/>
<xs:enumeration value="DIS"/>
</xs:restriction>
</xs:simpleType>
<!-- ... cut ... -->
<xs:complexType name="tSuper">
<xs:sequence>
<xs:element name="Text" type="xs:normalizedString"/>
</xs:sequence>
<xs:attribute name="dummy" type="tPredefinedEnum" use="optional"/>
</xs:complexType>
<xs:complexType name="tSub">
<xs:complexContent>
<xs:restriction base="tSuper">
<xs:sequence>
<xs:element name="Text" type="xs:normalizedString"/>
</xs:sequence>
<xs:attribute name="dummy" fixed="DIS"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
</xs:schema>
tSub is a restriction of tSuper, by fixing the value of the dummy attribute to DIS.
This seems perfectly valid to me and other validators do accept this. oXygen does however complain:
- [ OxygenBugs.xsd] E derivation-ok-restriction.2.1.2: Error for type 'tSub'. An attribute use in this type has a type which is not validly derived from the type of the matching attribute use in the base type. (33:18)
- [ OxygenBugs.xsd] E cos-particle-restrict.2: Forbidden particle restriction: 'any:choice,sequence,all,elt'. (30:30)
- [ OxygenBugs.xsd] E derivation-ok-restriction.5.3.2: Error for type 'tSub'. The particle of the type is not a valid restriction of the particle of the base. (30:30)
Are restrictions not supported or am I doing something wrong?
Thanks!
Chris
Dear Chris,
Oxygen uses the latest Xerces J (2.4.0) for validating schemas. It is true that other validators can say that your schema is valid and Xerces reports errors on it but in the majority of the cases I saw Xerces was right. The error codes you see immediatelly after the error level are the codes specified in
XML Schema Part 1: Structures http://www.w3.org/TR/xmlschema-1/ in the Appendix C: C Outcome Tabulations (normative) http://www.w3.org/TR/xmlschema-1/#outcomes. If you follow the error (derivation-ok-restriction.2.1.2) you will see:
C.4 Schema Component Constraints
derivation-ok-restriction
Derivation Valid (Restriction, Complex) - which links you to
http://www.w3.org/TR/xmlschema-1/#deriv ... estriction
There you should look at point 2.1.2:
Adding a type attribute pointing to the tPredefinedEnum will fix the problem. Therefore the following document:
will make oXygen happy and I guess the other validators as well.
We have on our todo list to add an option something like explain error for schema errors that should automatically present the corresponding parts from XML Schema Part 1: Structures/Outcome Tabulations (normative).
Best Regards,
George
Oxygen uses the latest Xerces J (2.4.0) for validating schemas. It is true that other validators can say that your schema is valid and Xerces reports errors on it but in the majority of the cases I saw Xerces was right. The error codes you see immediatelly after the error level are the codes specified in
XML Schema Part 1: Structures http://www.w3.org/TR/xmlschema-1/ in the Appendix C: C Outcome Tabulations (normative) http://www.w3.org/TR/xmlschema-1/#outcomes. If you follow the error (derivation-ok-restriction.2.1.2) you will see:
C.4 Schema Component Constraints
derivation-ok-restriction
Derivation Valid (Restriction, Complex) - which links you to
http://www.w3.org/TR/xmlschema-1/#deriv ... estriction
There you should look at point 2.1.2:
If you do not specify an attribute type then it is anySimpleType and this is not derived from tPredefinedEnum (B's type in your case).2 For each attribute use (call this R) in the {attribute uses} the appropriate case among the following must be true:
2.1 If there is an attribute use in the {attribute uses} of the {base type definition} (call this B) whose {attribute declaration} has the same {name} and {target namespace}, then all of the following must be true:
2.1.1 one of the following must be true:
2.1.1.1 B's {required} is false.
2.1.1.2 R's {required} is true.
2.1.2 R's {attribute declaration}'s {type definition} must be validly derived from B's {type definition} given the empty set as defined in Type Derivation OK (Simple) (§3.14.6).
Adding a type attribute pointing to the tPredefinedEnum will fix the problem. Therefore the following document:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<!-- fixed with oXygen :) -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="super" type="tSuper">
<xs:annotation>
<xs:documentation>Comment describing your root element</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="sub" type="tSub"/>
<xs:simpleType name="tPredefinedEnum">
<xs:restriction base="xs:Name">
<xs:enumeration value="CBR"/>
<xs:enumeration value="DIS"/>
</xs:restriction>
</xs:simpleType>
<!-- ... cut ... -->
<xs:complexType name="tSuper">
<xs:sequence>
<xs:element name="Text" type="xs:normalizedString"/>
</xs:sequence>
<xs:attribute name="dummy" type="tPredefinedEnum" use="optional"/>
</xs:complexType>
<xs:complexType name="tSub">
<xs:complexContent>
<xs:restriction base="tSuper">
<xs:sequence>
<xs:element name="Text" type="xs:normalizedString"/>
</xs:sequence>
<xs:attribute name="dummy" fixed="DIS" type="tPredefinedEnum"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
</xs:schema>
We have on our todo list to add an option something like explain error for schema errors that should automatically present the corresponding parts from XML Schema Part 1: Structures/Outcome Tabulations (normative).
Best Regards,
George
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