Xerces cos-nonambig schema validation error
This should cover W3C XML Schema, Relax NG and DTD related problems.
-
- Posts: 2
- Joined: Thu Jul 07, 2011 4:03 pm
Xerces cos-nonambig schema validation error
I'm struggling with an error message when validating an XSD. So I implemented an easy example of the same issue using DTD, which works fine.
Here's the DTD:
Converting this DTD to XSD (using Oxygen's "Generate/Convert Schema" function) results in this XSD:
This XSD does not validate. The error given is as follows:
Here's the DTD:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT ParaType1 (#PCDATA) >
<!ELEMENT ParaType2 (#PCDATA) >
<!ELEMENT List (ListItem+) >
<!ELEMENT ListItem ((ParaType1 | List)+ | (ParaType2 | List)+) >
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="ParaType1" type="xs:string"/>
<xs:element name="ParaType2" type="xs:string"/>
<xs:element name="List">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="ListItem"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="ListItem">
<xs:complexType>
<xs:choice>
<xs:choice maxOccurs="unbounded">
<xs:element ref="ParaType1"/>
<xs:element ref="List"/>
</xs:choice>
<xs:choice maxOccurs="unbounded">
<xs:element ref="ParaType2"/>
<xs:element ref="List"/>
</xs:choice>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
I don't understand why something as easy as (A | C)+ | (B | C)+ should produce an error. But I'm new to XSD so I hope there's just some trivial change needed. I would appreciate help on this matter.E [Xerces] cos-nonambig: List and List (or elements from their substitution group) violate "Unique Particle Attribution". During validation against this schema, ambiguity would be created for those two particles.
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Re: Xerces cos-nonambig schema validation error
Hello,
Please see http://www.w3.org/TR/xmlschema-1/#cos-nonambig
If you have a model like
then when a parser will encounter C as the first element it will not be able to match that against only one particle because both C will from your model will match it so the model is ambiguous.
You can write that in non ambiguous way as below:
As you can see these rewrites are not always easy in in some cases it is impossible to obtain a non ambiguous schema.
You can disable this check from the oXygen options [1] but that will not solve anything with the schema, only that you will not see these errors.
[1]
Options -> Preferences -- XML / XML Parser, disable the ...schema-full-checking option.
Best Regards,
George
Please see http://www.w3.org/TR/xmlschema-1/#cos-nonambig
If you have a model like
Code: Select all
(A | C)+ | (B | C)+
You can write that in non ambiguous way as below:
Code: Select all
(A, (A|C)*) |
(B, (B|C)*) |
(C+, (
(A, (A|C)*) |
(B, (B|C)*)
)?
)
You can disable this check from the oXygen options [1] but that will not solve anything with the schema, only that you will not see these errors.
[1]
Options -> Preferences -- XML / XML Parser, disable the ...schema-full-checking option.
Best Regards,
George
George Cristian Bina
-
- Posts: 2
- Joined: Thu Jul 07, 2011 4:03 pm
Re: Xerces cos-nonambig schema validation error
Hi George. Thank you so much! I've converted your answer into XSD and now everything works as it's supposed to. Here's the code:
The complexity of such a simple challenge is kind of a drawback from using XSD, but then again XSD has so many other benefits compared to DTD.
Thanks again for your help!
Code: Select all
<xs:element name="ListItem">
<xs:complexType>
<xs:choice>
<xs:sequence>
<xs:element ref="ParaType1"/>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="ParaType1"/>
<xs:element ref="List"/>
</xs:choice>
</xs:sequence>
<xs:sequence>
<xs:element ref="ParaType2"/>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="ParaType2"/>
<xs:element ref="List"/>
</xs:choice>
</xs:sequence>
<xs:sequence>
<xs:element ref="List" minOccurs="1" maxOccurs="unbounded"/>
<xs:choice minOccurs="0" maxOccurs="1">
<xs:sequence>
<xs:element ref="ParaType1"/>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="ParaType1"/>
<xs:element ref="List"/>
</xs:choice>
</xs:sequence>
<xs:sequence>
<xs:element ref="ParaType2"/>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="ParaType2"/>
<xs:element ref="List"/>
</xs:choice>
</xs:sequence>
</xs:choice>
</xs:sequence>
</xs:choice>
</xs:complexType>
</xs:element>
Thanks again for your help!
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Re: Xerces cos-nonambig schema validation error
You may want to review also
http://www.w3.org/TR/xml/#determinism
and Tim Bray comments on this
http://www.xml.com/axml/notes/Determinism.html
So basically the spec says that if ambiguous content models are created some parsers may report an error.
As an alternative you may want to explore also
Relax NG
Schematron
or maybe XML Schema 1.1
Relax NG allows ambiguous content and you can express that content model directly.
Schematron can be used in addition to XML Schema and you can have a simple model in the XML Schema that will say (A | B | C)+ and add a Schematron rule that asserts that both A and B are not present, otherwise it will fail rising an error.
XML Schema 1.1 adds some features of Schematron and you can have assertions directly in XML Schema 1.1.
Best Regards,
George
http://www.w3.org/TR/xml/#determinism
and Tim Bray comments on this
http://www.xml.com/axml/notes/Determinism.html
So basically the spec says that if ambiguous content models are created some parsers may report an error.
As an alternative you may want to explore also
Relax NG
Schematron
or maybe XML Schema 1.1
Relax NG allows ambiguous content and you can express that content model directly.
Schematron can be used in addition to XML Schema and you can have a simple model in the XML Schema that will say (A | B | C)+ and add a Schematron rule that asserts that both A and B are not present, otherwise it will fail rising an error.
XML Schema 1.1 adds some features of Schematron and you can have assertions directly in XML Schema 1.1.
Best Regards,
George
George Cristian Bina
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