Invalid Schema

This should cover W3C XML Schema, Relax NG and DTD related problems.
twcook
Posts: 23

Invalid Schema

Tue Sep 11, 2012 3:59 pm

This is essentially the same issue I had under the Invalid Restriction subject in this forum. However, I have created a smaller version of the two schemas as an easier way to look at the problem.

The base schema aka. reference model.

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
   
    <xs:complexType name="Any" abstract="true">
        <xs:sequence>
            <xs:element name="A-data" type="xs:string"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="DT1">
        <xs:complexContent>
            <xs:extension base="Any">
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
   
    <xs:complexType name="DT1-1">
        <xs:complexContent>
            <xs:extension base="DT1">
                <xs:sequence>
                    <xs:element name="dt-data" type="xs:string"/>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
   

    <xs:complexType name="Locate" abstract="true">
        <xs:sequence>
            <xs:element name="L-data" type="xs:string"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="Definition" abstract="true">
        <xs:complexContent>
            <xs:extension base="Locate">
             </xs:extension>
        </xs:complexContent>
    </xs:complexType>
   

    <xs:complexType name="Item" abstract="true">
        <xs:complexContent>
            <xs:extension base="Definition">
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>

    <xs:complexType name="Item1">
        <xs:complexContent>
            <xs:extension base="Item">
                <xs:sequence>
                    <xs:element name="I-data" type="Any"/>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
   
    <xs:complexType name="Entry" abstract="true">
        <xs:complexContent>
            <xs:extension base="Definition">
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
   
    <xs:complexType name="Entry1">
        <xs:complexContent>
            <xs:extension base="Entry">
                <xs:sequence>
                    <xs:element name="E-data" type="xs:string"/>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
   
   
    <xs:complexType name="ccdType">
        <xs:sequence>
            <xs:element name="defin" type="Locate"/>
        </xs:sequence>
    </xs:complexType>
   
</xs:schema>



The constraint model:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
    <xs:include schemaLocation="rm-test.xsd"/>
   
    <xs:element name="CCD1" type="Y"/>
   
    <xs:complexType name="Y">
        <xs:complexContent>
            <xs:restriction base="ccdType">
                <xs:sequence>
                    <xs:element name="defin" type="Z"/>
                </xs:sequence>
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>
   

    <xs:complexType name="Z">
        <xs:complexContent>
            <xs:restriction base="Item1">
                <xs:sequence>
                    <xs:element name="L-data" type="xs:string" fixed="My L string."/>
                    <xs:element name="I-data" type="X"/>
                </xs:sequence>
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>

    <xs:complexType name="X">
        <xs:complexContent>
            <xs:restriction base="DT1-1">
                <xs:sequence>
                    <xs:element name="A-data" type="xs:string" fixed="My A string."/>
                    <xs:element name="dt-data" type="xs:string" fixed="A dt string."/>
                </xs:sequence>
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>
   
   
   
   
</xs:schema>



Oxygen (Saxon-EE) gives this error:
F [Saxon-EE 9.4.0.3] The content model of the complex type Z is not a valid restriction of the content model of the type Item1. Definition of element I-data differs between the restricted type and the base type. Type of element in restricted content model is not validly derived from the type of the corresponding element in base content model


Here are a couple of images of a logical model for the two schemas. They may or may not help.
http://www.hkcr.net/docs/tmp


If I generate an instance (using Oxygen) for ccd-test.xsd Of course Oxygen won't validate it because it says the schema is invalid.

xmllint and xmlstarlet both validate the instance against ccd-test.xsd

I was unable to discover how I might execute Saxon-EE outside of Oxygen. ???

The questions are:
1) are xmllint and xmlstarlet too forgiving?
2) is there an issue with Saxon?
3) is there an issue with Saxon inside Oxygen?
4) am I just totally missing something obvious?

Thanks,
Tim
adrian
Posts: 2442

Re: Invalid Schema

Tue Sep 11, 2012 5:43 pm

Hi,

1. I believe they don't validate the schema, they probably build the XML model from the schema as best as they can and validate the XML against that model.
2. As far as I know there isn't.
3. No, it should perform the same from the command line and from Oxygen.
4. I believe you have made some mistakes.

The error regarding the complex type Z appears because you have changed the type of "I-data". In the complex type Item1 the type of "I-data" is "Any" but in "Z", you've changed that type to "X" within the restriction. These two types are not related, "X" should be defined as a restriction of "Any" for this to work.

The same problem appears in complex type "Y" and is more obvious here. The base type of the restriction is "ccdType" where "defin" has the type "Locate", but in the restriction you changed the type of "defin" to "Z" which is unrelated to "Locate". Again, "Z" should be defined as a restriction of type "Locate" for this to work.

Regards,
Adrian

PS: Note that you can't use the edition of Saxon-EE that is bundled with Oxygen from the command line (outside of Oxygen). It is only licensed to be used within Oxygen. If you want to run it from the command line you need a separate license from Saxonica.
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
twcook
Posts: 23

Re: Invalid Schema

Wed Sep 12, 2012 11:11 pm

Thanks for the prompt reply Adrian.

The items you mentioned are related. They are derived from the parent. However, as was pointed out to me on the xml-dev list; using xs:extension and then xs:restriction breaks the chain of ancestry. It is rather obscure in the specs. But Micheal Kay walked me through it. It can be found under the subject "Perplexing Invalid SChema" on that mailing list.

Now, back to work trying to figure out how to implement this model.

Cheers,
Tim
twcook
Posts: 23

Re: Invalid Schema

Thu Sep 13, 2012 3:03 pm

Okay, I managed to create an approach that seems to work using ref="" and substitutiongroups. Here is a sample base schema followed by a constraint schema.

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">

   
   <xs:complexType  name="AnyType" abstract="true">
     <xs:sequence>
       <xs:element name="A-data" type="xs:int" minOccurs="1" maxOccurs="unbounded"/>
     </xs:sequence>
   </xs:complexType>
    <xs:element  name="Any" type="AnyType" abstract="true"/>
       
   <xs:complexType name="DT1Type">
     <xs:complexContent>
       <xs:extension base="AnyType"> 
         <xs:sequence>
             <xs:element name="dt1-data" type="xs:string" minOccurs="1" maxOccurs="unbounded"/>
          </xs:sequence>
         </xs:extension>
       </xs:complexContent>
   </xs:complexType>
   <xs:element name="DT1" type="DT1Type" substitutionGroup="Any"/>   

        <xs:complexType name="DT1-1Type">
            <xs:complexContent>
                <xs:extension base="AnyType"> 
                    <xs:sequence>
                        <xs:element name="dt1-1-data" type="xs:date"  minOccurs="1" maxOccurs="2"/>
                    </xs:sequence>
                </xs:extension>
            </xs:complexContent>
        </xs:complexType>
       <xs:element  name="DT1-1" type="DT1-1Type" substitutionGroup="Any"/>   

    <xs:complexType name="DefinitionType" abstract="true"/>
    <xs:element name="Definition" type="DefinitionType"/>

    <xs:element  name="Item" abstract="true" type="DefinitionType"/>
   
    <xs:complexType name="ClusterType">
        <xs:complexContent>
            <xs:extension base="DefinitionType">
                <xs:sequence>
                    <xs:element ref="Item" minOccurs="1" maxOccurs="unbounded"/> <!--Items-->
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
    <xs:element  name="Cluster" type="ClusterType" substitutionGroup="Item Definition"/>

        <xs:complexType name="ElementType">
            <xs:complexContent>
                <xs:extension base="DefinitionType">
                    <xs:sequence>
                        <xs:element ref="Any" minOccurs="1" maxOccurs="1"/> <!--DataTyype-->
                    </xs:sequence>
                </xs:extension>
            </xs:complexContent>
        </xs:complexType>
        <xs:element  name="Element" type="ElementType" substitutionGroup="Item Definition"/>
           
           
    <xs:element name="Entry" abstract="true" type="DefinitionType" />
   

    <xs:complexType name="CareEntryType">
        <xs:complexContent>
            <xs:extension base="DefinitionType">
                <xs:sequence>
                    <xs:element name="CE-data" type="xs:string"/>
                </xs:sequence>
        </xs:extension>
        </xs:complexContent>
    </xs:complexType>
    <xs:element name="CareEntry" type="CareEntryType" substitutionGroup="Entry Definition"/>

    <xs:complexType name="ccdType">
        <xs:sequence>
            <xs:element ref="Definition"/>
        </xs:sequence>
    </xs:complexType>

</xs:schema>


Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
    <xs:include schemaLocation="rm2.xsd"/>
   
    <xs:element name="CCD2-02" type="Y-Type"/>
   
    <xs:complexType name="Y-Type">
        <xs:sequence>
          <xs:element ref="Z"/>
        </xs:sequence>
    </xs:complexType>
   
    <xs:complexType name="Z-Type">
        <xs:complexContent>
            <xs:restriction base="ClusterType">
                <xs:sequence>
                    <xs:element ref="E" minOccurs="1" maxOccurs="1"/> <!--Items-->
                    <xs:element ref="E2" minOccurs="1" maxOccurs="1"/> <!--Items-->
                </xs:sequence>
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>
    <xs:element name="Z" type="Z-Type" substitutionGroup="Definition"/>
   
    <xs:complexType name="E-Type">
        <xs:complexContent>
            <xs:restriction base="ElementType">
                <xs:sequence>
                    <xs:element ref="D" minOccurs="1" maxOccurs="1"/> <!--DataTyype-->
                </xs:sequence>
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>
    <xs:element name="E" type="E-Type" substitutionGroup="Element"/>

    <xs:complexType name="E-Type2">
        <xs:complexContent>
            <xs:restriction base="ElementType">
                <xs:sequence>
                    <xs:element ref="D2" minOccurs="1" maxOccurs="1"/> <!--DataTyype-->
                </xs:sequence>
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>
    <xs:element name="E2" type="E-Type2" substitutionGroup="Element"/>
   


    <xs:complexType name="D-Type">
        <xs:complexContent>
            <xs:restriction base="DT1Type">
                <xs:sequence>
                    <xs:element name="A-data" type="xs:int" minOccurs="1"/>
                    <xs:element name="dt1-data" type="xs:string"/>
                </xs:sequence>
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>
    <xs:element name="D" type="D-Type" substitutionGroup="Any"/>
   
    <xs:complexType name="D-Type2">
        <xs:complexContent>
            <xs:restriction base="DT1-1Type">
                <xs:sequence>
                    <xs:element name="A-data" type="xs:int" minOccurs="1"/>
                    <xs:element name="dt1-1-data" type="xs:date"/>
                </xs:sequence>
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>
    <xs:element name="D2" type="D-Type2" substitutionGroup="Any"/>
   


</xs:schema>


Both of those validate and in instances I can test for valid and invalid data. All seems to work fine.

So, the challenge is to move this to my real-life implementation. Below is the base schema for that. I get an invalid schema message but the error is 'null'. So I have no idea where to look for a problem. I have visually gone over it twice and can't see any errors. Thoughts?

System ID: /home/tim/MLHIM/mlhim-specs/schemas/mlhim2.xsd
Main validation file: /home/tim/MLHIM/mlhim-specs/schemas/mlhim2.xsd
Engine name: Saxon-EE 9.4.0.3
Severity: error


The schema is too large to include here. It is publicly available at:
http://www.mlhim.org/xmls/mlhim2/2_4_0/mlhim2.xsd/at_download/file

Thanks,
Tim
adrian
Posts: 2442

Re: Invalid Schema

Thu Sep 13, 2012 5:15 pm

Hi,

Saxon seems to have an issue with your substitution groups. It fails with a NullPointerException when looking for cycles. I'll report this to Saxonica to be investigated and fixed.

I've tried validating with Xerces 2.11 (XSD 1.1 aware) with Oxygen v14.1 (still in development) and I get a lot of errors like this one:
Engine name: Xerces
Severity: error
Description: cos-nonambig: "http://www.mlhim.org/xmls/mlhim2/2_4_0":ReferenceRange and "http://www.mlhim.org/xmls/mlhim2/2_4_0":ReferenceRange (or elements from their substitution group) violate "Unique Particle Attribution". During validation against this schema, ambiguity would be created for those two particles.
URL: http://www.w3.org/TR/xmlschema11-1/#cos-nonambig

This particular error seems to be caused by the fact that in the complex type DvOrderedType you have a sequence that refers the same element (mlhim2:ReferenceRange) twice, thus violating the "Unique Particle Attribution" rule.

Code: Select all

<xs:element maxOccurs="1" minOccurs="0" ref="mlhim2:ReferenceRange">
    <!--name="normal-range"-->
    <xs:annotation>
        <xs:documentation>name="normal-range": Optional normal range.
        </xs:documentation>
    </xs:annotation>
</xs:element>
<xs:element maxOccurs="unbounded" minOccurs="0" ref="mlhim2:ReferenceRange">
    <!--name="other-reference-ranges"-->
    <xs:annotation>
        <xs:documentation>name="other-reference-ranges": Optional list of
            ReferenceRanges for this value in its particular measurement context
        </xs:documentation>
    </xs:annotation>
</xs:element>

Something similar happens in PartyProxyType with the reference to mlhim2:DvURI and in ElementType with the reference to mlhim2:DvAny, but these are caused by extensions.


Then for all complex types from MSKType down to and including NAType I have:
Engine name: Xerces
Severity: error
Description: derivation-ok-restriction.5.4.2: Error for type 'INVType'. The particle of the type is not a valid restriction of the particle of the base.
URL: http://www.w3.org/TR/xmlschema11-1/#der ... estriction

Let me know, if you'd like beta access to a beta build of Oxygen v14.1. It might be easier to check these problems by yourself.

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
twcook
Posts: 23

Re: Invalid Schema

Thu Sep 13, 2012 5:56 pm

Let me know, if you'd like beta access to a beta build of Oxygen v14.1. It might be easier to check these problems by yourself.


That would be great. I really need to get this working.

Thanks,
Tim
adrian
Posts: 2442

Re: Invalid Schema

Tue Sep 18, 2012 11:49 am

Hi,

Did you make progress with the v14.1 beta?

If you encounter any issues with this beta please report them to our support email address: support AT oxygenxml DOT com

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

Return to “XML Schemas”

Who is online

Users browsing this forum: No registered users and 0 guests