Invalid Restriction?

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

Invalid Restriction?

Sat Aug 25, 2012 6:14 pm

The Error:

Code: Select all

System ID: /home/tim/MLHIM/slot-example/ccd_8057ea74_47d8_470d_b9b9_a0b9a8e3b8c0.xsd
Main validation file: /home/tim/MLHIM/slot-example/ccd_8057ea74_47d8_470d_b9b9_a0b9a8e3b8c0.xsd
Engine name: Saxon-EE 9.4.0.3
Severity: fatal
Description: The content model of the complex type ct_05363e2b_d67c_4831_b224_7e38d9b283da is not a valid restriction of the content model of the type DvStringType. Restricted type allows element DvString_dv where the base type does not
Start location: 63:0


ct_05363e2b_d67c_4831_b224_7e38d9b283da

Code: Select all

   <xs:complexType name="ct_05363e2b_d67c_4831_b224_7e38d9b283da">
      <xs:complexContent>
         <xs:restriction base="mlhim2:DvStringType">
            <xs:sequence>
               <xs:element name="DvString_dv"  minOccurs="1"  maxOccurs="1" type="xs:string"/>
               <xs:element name="data_name" type="xs:string" maxOccurs="1" minOccurs="1" fixed="Slot Filler"/>
            </xs:sequence>
         </xs:restriction>
      </xs:complexContent>
   </xs:complexType>


Base type: DvStringType (mlhim2.xsd)

Code: Select all

<xs:complexType name="DvStringType">
<xs:annotation>
<xs:documentation>
The string data type can contain characters, line feeds, carriage returns, and tab characters.
</xs:documentation>
</xs:annotation>
<xs:complexContent>
<xs:extension base="mlhim2:DvAnyType">
<xs:sequence>
<xs:element minOccurs="0" name="DvString_dv" type="xs:string"/>
<xs:element maxOccurs="1" minOccurs="0" name="language" type="xs:language"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>


Base type For DvStringType is DvAnyType (mlhim2.xsd):

Code: Select all

<xs:complexType abstract="true" name="DvAnyType">
<xs:annotation>
<xs:documentation>
Serves as a common ancestor of all datatypes in MLHIM models.

</xs:documentation>
</xs:annotation>
<xs:sequence>
<xs:element name="data_name" type="xs:string" maxOccurs="1" minOccurs="1"/>
<xs:element maxOccurs="1" minOccurs="0" name="ev" nillable="true" type="mlhim2:ExceptionalValueType"/>
<xs:element maxOccurs="1" minOccurs="0" name="valid_time_begin" nillable="true" type="xs:dateTime"/>
<xs:element maxOccurs="1" minOccurs="0" name="valid_time_end" nillable="true" type="xs:dateTime"/>
</xs:sequence>
</xs:complexType>



There are a number of "datatypes" in the schema (mlhim2.xsd) and they all exhibit similar errors in the restrictions schemas similar to ccd_8057ea74_47d8_470d_b9b9_a0b9a8e3b8c0.xsd Both mlhim2.xsd and the restrictions schemas have targetNamespace="http://www.mlhim.org/xmls/mlhim2/2_3_1"
and elementFormDefault="qualified"
entries.

Any ideas where to start on this?

Thanks,
Tim

PS.My other issue re:Derivation levels was solved by setting the default parser to Saxon EE and the version to 1.1 But it hasn't passed moderation yet at the time I am posting this one.
adrian
Posts: 2443

Re: Invalid Restriction?

Mon Aug 27, 2012 1:13 pm

Hi,

My best guess is it's a namespace issue. You cannot restrict a type from a different namespace because of the XML Schema limitation which does not allow you to declare elements from a different namespace other than the target namespace (or no-namespace).

To clarify, "mlhim2.xsd" has elementFormDefault="qualified" and the targetNamespace="http://www.mlhim.org/xmls/mlhim2/2_3_1". This means all the local elements from the schema are declared in the target namespace. So, DvAnyType and DvStringType declare local elements(data_name, DvString_dv, etc) in the target namespace, "http://www.mlhim.org/xmls/mlhim2/2_3_1".

My guess is you then import "mlhim2.xsd" in "ccd_8057ea74_47d8_470d_b9b9_a0b9a8e3b8c0.xsd" which may have a different target namespace or maybe elementFormDefault="unqualified" (I can't see the schema root in your samples.
So, when you try to create the restriction from this new schema, you are actually declaring "DvString_dv" and "data_name" from this schema's namespace. Obviously this won't work, elements from different namespaces are actually considered different elements (the namespace is more important than the local name).

You could resolve this in two ways:
- by including "mlhim2.xsd" instead of importing it, but then you need the same target namespace, so it might not be a good solution
- by using elementFormDefault="unqualified" in both schemas, thus having all local elements in no-namespace and thus being able to create that restriction. Might not be possible if the base schema is standardized.

Neither are great solutions, but they also work with XSD 1.0. XSD 1.1 might have a better solution for this, but I'm not familiar with all its intricacies.

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

Re: Invalid Restriction?

Mon Aug 27, 2012 6:18 pm

Thanks for the explanation. It helped with my understanding.
However, I don't think we have hit on the problem yet. They both have the same namespace and I use include for mlhim2.xsd.

Just for some context, the base schema is a very broad set of definitions and the restriction schemas (ccd_???) represent specific concepts built using the base structures.

The base schema mlhim2.xsd is available at:
http://www.mlhim.org/xmls/mlhim2/2_3_1/mlhim2.xsd

Here is a derivative/restriction schema:
ccd_f9493153_8960_4974_8725_3bf824319ac8.xsd

Code: Select all

<?xml version="1.1" encoding="UTF-8"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
   xmlns:mlhim2="http://www.mlhim.org/xmls/mlhim2/2_3_1" elementFormDefault="qualified"
   targetNamespace="http://www.mlhim.org/xmls/mlhim2/2_3_1">

   <xs:annotation>
      <xs:documentation source="http://www.mlhim.org" xml:lang="en-US">
      This is a Cluster Example Concept Constraint Definition schema file (CCD).

      <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/">

   <rdf:Description rdf:about="http://www.hkcr.net/ccd/ccd_f9493153_8960_4974_8725_3bf824319ac8">
     <dc:title>Cluster Example</dc:title>
     <dc:creator>Timothy W. Cook &lt;timothywayne.cook@gmail.com&gt; </dc:creator>
          <dc:contributor>None</dc:contributor>
          <dc:subject>Cluster CCD</dc:subject>
     <dc:source>My Brain</dc:source>
     <dc:rights>CC-BY http://creativecommons.org/licenses/by/3.0/</dc:rights>
     <dc:relation>None</dc:relation>
     <dc:coverage>Universal</dc:coverage>
     <dc:type>MLHIM Concept Constraint Definition (CCD)</dc:type>
     <dc:identifier>ccd_f9493153_8960_4974_8725_3bf824319ac8</dc:identifier>
     <dc:description>Experimental Cluster CCD</dc:description>
     <dc:publisher>MLHIM</dc:publisher>
     <dc:date>2012-08-24</dc:date>
     <dc:format>text/xml</dc:format>
     <dc:language>en-US</dc:language>
   </rdf:Description>

   </rdf:RDF>

    </xs:documentation>
   </xs:annotation>

   <xs:include schemaLocation="http://www.mlhim.org/xmls/mlhim2/2_3_1/mlhim2.xsd"/>

   <xs:element name="ccd_f9493153_8960_4974_8725_3bf824319ac8"
      type="mlhim2:ct_a575df1d_20fd_4d65_aba3_4ad550cd7230"/>

   <xs:complexType name="ct_a575df1d_20fd_4d65_aba3_4ad550cd7230">
      <xs:complexContent>
         <xs:restriction base="mlhim2:CCDType">
            <xs:sequence>
               <xs:element name="definition" minOccurs="1" maxOccurs="1" type="mlhim2:ct_eb02eb6b_c376_4557_92b2_1d197fc25027"/>
            </xs:sequence>
         </xs:restriction>
      </xs:complexContent>
   </xs:complexType>

   <xs:complexType name="ct_eb02eb6b_c376_4557_92b2_1d197fc25027">
      <xs:complexContent>
         <xs:restriction base="mlhim2:ClusterType">
            <xs:sequence>
               <xs:element maxOccurs="1" minOccurs="1" name="cluster_subject" type="xs:string"   fixed="Top Cluster"/>
               <xs:element maxOccurs="1" minOccurs="1" name="items" type="mlhim2:ct_013f4560_9b34_4081_9162_e58245cec514"/>
            </xs:sequence>
         </xs:restriction>
      </xs:complexContent>
   </xs:complexType>



   <!--Items List-->
   <xs:complexType name="ct_013f4560_9b34_4081_9162_e58245cec514">
      <xs:complexContent>
         <xs:extension base="mlhim2:ItemType">
            <xs:sequence>
               <xs:element name="String_One"  minOccurs="1"  maxOccurs="1" type="mlhim2:ct_72081594_72e8_4773_b36d_c41e438a0929"/>
               <xs:element name="String_Two"  minOccurs="1"  maxOccurs="1" type="mlhim2:ct_05363e2b_d67c_4831_b224_7e38d9b283db"/>            </xs:sequence>
         </xs:extension>
      </xs:complexContent>
   </xs:complexType>
   
   <!--Element One-->
   <xs:complexType name="ct_72081594_72e8_4773_b36d_c41e438a0929">
      <xs:complexContent>
         <xs:restriction base="mlhim2:ElementType">
            <xs:sequence>
               <xs:element name="Element_dv"  minOccurs="1"  maxOccurs="1" type="mlhim2:ct_e6c3c31f_58d3_45d6_8b4d_7694c81c8bcb"/>
            </xs:sequence>
         </xs:restriction>
      </xs:complexContent>
   </xs:complexType>
   
   
   <xs:complexType name="ct_e6c3c31f_58d3_45d6_8b4d_7694c81c8bcb">
      <xs:complexContent>
         <xs:restriction base="mlhim2:DvStringType">
            <xs:sequence>
               <xs:element name="DvString_dv"  minOccurs="1"  maxOccurs="1" type="xs:string"/>
               <xs:element name="data_name" type="xs:string" maxOccurs="1" minOccurs="1" fixed="String One"/>
            </xs:sequence>
         </xs:restriction>
      </xs:complexContent>
   </xs:complexType>
   
   <!--Element Two-->
   <xs:complexType name="ct_05363e2b_d67c_4831_b224_7e38d9b283db">
      <xs:complexContent>
         <xs:restriction base="mlhim2:ElementType">
            <xs:sequence>
               <xs:element name="Element_dv"  minOccurs="1"  maxOccurs="1" type="mlhim2:ct_90e6df33_fe19_458f_9e3f_2e6ee3db75fa"/>
            </xs:sequence>
         </xs:restriction>
      </xs:complexContent>
   </xs:complexType>
   
   
   <xs:complexType name="ct_90e6df33_fe19_458f_9e3f_2e6ee3db75fa">
      <xs:complexContent>
         <xs:restriction base="mlhim2:DvStringType">
            <xs:sequence>
               <xs:element name="DvString_dv"  minOccurs="1"  maxOccurs="1" type="xs:string"/>
               <xs:element name="data_name" type="xs:string" maxOccurs="1" minOccurs="1" fixed="String Two"/>
            </xs:sequence>
         </xs:restriction>
      </xs:complexContent>
   </xs:complexType>
   
</xs:schema>




Thanks in advance for your help.

BTW: Oxygen is an awesome tool! (but I guess you knew that) :D
twcook
Posts: 23

Re: Invalid Restriction?

Mon Aug 27, 2012 6:24 pm

Just to be more specific. In the above schema;

ct_e6c3c31f_58d3_45d6_8b4d_7694c81c8bcb
and
ct_90e6df33_fe19_458f_9e3f_2e6ee3db75fa

each give the same error:

Code: Select all

F [Saxon-EE 9.4.0.3] The content model of the complex type ct_90e6df33_fe19_458f_9e3f_2e6ee3db75fa is not a valid restriction of the content model of the type DvStringType. Restricted type allows element DvString_dv where the base type does not


Thanks,
Tim
adrian
Posts: 2443

Re: Invalid Restriction?

Tue Aug 28, 2012 3:58 pm

Hi,

I stared at the schema for a long while :shock:, but I eventually figured it out.
Because you're using a sequence, the order of the elements from the restriction is significant.
So you simply have to change the order of the elements in the restriction to obey the one from the base type (caused by the extension from that type).
So, instead of:

Code: Select all

<xs:restriction base="mlhim2:DvStringType">
    <xs:sequence>
        <xs:element name="DvString_dv"  minOccurs="1"  maxOccurs="1" type="xs:string"/>
        <xs:element name="data_name" type="xs:string" maxOccurs="1" minOccurs="1" fixed="String Two"/>
    </xs:sequence>
</xs:restriction>

you have to use:

Code: Select all

<xs:restriction base="mlhim2:DvStringType">
    <xs:sequence>
        <xs:element name="data_name" type="xs:string" maxOccurs="1" minOccurs="1" fixed="String Two"/>
        <xs:element name="DvString_dv"  minOccurs="1"  maxOccurs="1" type="xs:string"/>
    </xs:sequence>
</xs:restriction>

In addition, I'd like to point out that the version from the XML declaration that you're using (<?xml version="1.1" encoding="UTF-8"?>) does not reflect the XSD version, but the XML version. So, if your intention was to specify XSD 1.1 with that, that's not the correct solution and I'd recommend to use version="1.0" instead to avoid confusion.

Regarding the namespace discussion (which turned out to be a bad lead in the end and did not apply to your actual problem), I'd just like to add that for XSD 1.1 there is a simpler solution. For XSD 1.1 you can specify a targetNamespace attribute for each of the locally declared elements and this way you can declare them in the appropriate namespace.

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

Re: Invalid Restriction?

Tue Aug 28, 2012 4:55 pm

Thanks so much Adrian. I actually thought the reverse order was correct.

So to state the answer; elements that are inherited (is that the correct word in XSD?) in an extension, are listed first when used in a later restriction sequence.

Regarding the namespace discussion (which turned out to be a bad lead in the end and did not apply to your actual problem), I'd just like to add that for XSD 1.1 there is a simpler solution. For XSD 1.1 you can specify a targetNamespace attribute for each of the locally declared elements and this way you can declare them in the appropriate namespace.


Well, the namespace discussion was still helpful for my understanding. But, I am not sure I understand what you are saying here. I actually do want (AFAIK) all of them to be in the mlhim2 namespace. Is there a reason I would want a different namespace for the restriction schemas?

Regarding the version number. Yes, I wanted to express XSD 1.1. In many cases, the modeler will need to use assertions in the restriction schemas. So how does one indicate that XML Schema 1.1 is in use?

Thanks again for the awesome support.

--Tim
twcook
Posts: 23

Re: Invalid Restriction?

Tue Aug 28, 2012 5:07 pm

Regarding the version number. Yes, I wanted to express XSD 1.1. In many cases, the modeler will need to use assertions in the restriction schemas. So how does one indicate that XML Schema 1.1 is in use?


I believe I found the answer in http://www.w3.org/2007/XMLSchema-versioning/

Thanks,
Tim
adrian
Posts: 2443

Re: Invalid Restriction?

Tue Aug 28, 2012 5:50 pm

Hi,

twcook wrote:Well, the namespace discussion was still helpful for my understanding. But, I am not sure I understand what you are saying here. I actually do want (AFAIK) all of them to be in the mlhim2 namespace. Is there a reason I would want a different namespace for the restriction schemas?

Sorry about the confusion, the solution for XSD 1.1 addresses the situation where you import (not include as in your case) a schema and you need to extend or restrict a type from that schema that has local elements from a different namespace. For XSD 1.0 it's more complicated as I initially mentioned, but I wanted to also provide the appropriate solution for XSD 1.1 (which I did not know about at that time).
If you want all the elements in the same namespace and use an include, this solution is of no use to you. I just mentioned it for future reference (or in case anyone stumbles upon a similar problem).

twcook wrote:Regarding the version number. Yes, I wanted to express XSD 1.1. In many cases, the modeler will need to use assertions in the restriction schemas. So how does one indicate that XML Schema 1.1 is in use?

twcook wrote:I believe I found the answer in http://www.w3.org/2007/XMLSchema-versioning/

That's probably the only solution that can be used currently. What that does though is that it specifies which parts of the schema require support for a specific version of XML Schema.

That solution might not work for all processors because it's not included in the XML schema specification and some might not implement it. I see that it works for Saxon 9.x, but not for Xerces 2.9.
And by works I mean that if you specify vc:minVersion="1.1", Saxon will completely ignore that element (or entire schema), if it (Saxon) is configured for XSD version 1.0. So this might not be as helpful as you would think.

A comment at the beginning of the schema will probably be more helpful that any of these.

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 2 guests