W3C home > Mailing lists > Public > xmlschema-dev@w3.org > January 2012

Re: SimpleType not enforced for extended element

From: G. Ken Holman <gkholman@CraneSoftwrights.com>
Date: Thu, 05 Jan 2012 21:55:30 -0500
Message-Id: <7.0.1.0.2.20120105215127.046606c8@wheresmymailserver.com>
To: xmlschema-dev@w3.org
At 2012-01-05 17:48 -0700, Karl Stubsjoen wrote:
>I have an element that extends a complex type but the additional
>attribute with a simple type definition is not being enforced.  The
>attribute is enforced, just not it's simple type.  Have I defined
>something incorrectly?

I think this is one of those "don't kick yourself" problems.

>Here they are:
>
><!-- to be used in extension below -->
>     <xs:complexType name="ProjXm_QueryType">
>         <xs:sequence>
>             <xs:element ref="command"/>
>             <xs:element ref="parameters"/>
>             <xs:element ref="fields" minOccurs="0"/>
>         </xs:sequence>
>     </xs:complexType>
>
>
><!-- extends the above and adds a name attribute of specified simple type -->
>     <xs:element name="SharedDB">
>         <xs:complexType>
>             <xs:complexContent>
>                 <xs:extension base="ProjXm_QueryType">
>                     <xs:attribute name="name"
>type="simpleType_SharedDBQueries" />

Here you've just augmented your element with an attribute ....

>                 </xs:extension>
>             </xs:complexContent>
>         </xs:complexType>
>     </xs:element>
>
><!-- expected values for name attribute ->
>     <xs:simpleType name="simpleType_SharedDBQueries">
>         <xs:restriction base="xs:NCName">
>             <xs:enumeration value="insert"/>
>             <xs:enumeration value="update"/>
>         </xs:restriction>
>     </xs:simpleType>
>
>
><!-- sample xml (snipped) -->
>     <SharedDB>
>         <command>
>             <name>insertxx</name><!-- would expect validation to 
> fail here -->

... but you've put an element in your XML for testing.

>             <type>StoredProcedure</type>
>             <action>NonQuery</action>
>         </command>
>         <parameters>
>     ...
>     </SharedDB>

I think if you had <SharedDB name="insertxx"> you would find the 
problem NCName flagged.  I just copied your exact schema fragment 
into a bogus schema below and you'll see the attribute is being 
validated by both Xerces and Saxon.

I hope this helps.

. . . . . . . . . . . . . Ken

~/t/ftemp $ cat karl.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
   elementFormDefault="qualified">
     <!-- to be used in extension below -->
     <xs:complexType name="ProjXm_QueryType">
         <xs:sequence>
             <xs:element ref="command"/>
             <xs:element ref="parameters"/>
             <xs:element ref="fields" minOccurs="0"/>
         </xs:sequence>
     </xs:complexType>


<!-- extends the above and adds a name attribute of specified simple type -->
     <xs:element name="SharedDB">
         <xs:complexType>
             <xs:complexContent>
                 <xs:extension base="ProjXm_QueryType">
                     <xs:attribute name="name"
type="simpleType_SharedDBQueries" />
                 </xs:extension>
             </xs:complexContent>
         </xs:complexType>
     </xs:element>

<!-- expected values for name attribute -->
     <xs:simpleType name="simpleType_SharedDBQueries">
         <xs:restriction base="xs:NCName">
             <xs:enumeration value="insert"/>
             <xs:enumeration value="update"/>
         </xs:restriction>
     </xs:simpleType>

     <xs:element name="command">
       <xs:complexType/>
     </xs:element>
     <xs:element name="fields">
       <xs:complexType/>
     </xs:element>
     <xs:element name="parameters">
       <xs:complexType/>
     </xs:element>
</xs:schema>
~/t/ftemp $ cat karl.xml
<?xml version="1.0" encoding="UTF-8"?>
<SharedDB name="insert">
   <command/>
   <parameters/>
</SharedDB>
~/t/ftemp $ w3cschema karl.xsd karl.xml
Xerces...
Attempting validating, namespace-aware parse
Parse succeeded (0.131) with no errors and no warnings.
Saxon...
No validation errors
~/t/ftemp $ cat karlbad1.xml
<?xml version="1.0" encoding="UTF-8"?>
<SharedDB namex="insert">
   <command/>
   <parameters/>
</SharedDB>
~/t/ftemp $ w3cschema karl.xsd karlbad1.xml
Xerces...
Attempting validating, namespace-aware parse
Error:file:///Users/admin/t/ftemp/karlbad1.xml:2:26:cvc-complex-type.3.2.2: 
Attribute 'namex' is not allowed to appear in element 'SharedDB'.
Parse succeeded (0.135) with 1 error and no warnings.
Saxon...
Validation error on line 2 column 26 of karlbad1.xml:
   Attribute @namex is not allowed on element <SharedDB> (See
   http://www.w3.org/TR/xmlschema-1/#cvc-complex-type clause 3)
No validation errors
~/t/ftemp $ cat karlbad2.xml
<?xml version="1.0" encoding="UTF-8"?>
<SharedDB name="insertx">
   <command/>
   <parameters/>
</SharedDB>
~/t/ftemp $ w3cschema karl.xsd karlbad2.xml
Xerces...
Attempting validating, namespace-aware parse
Error:file:///Users/admin/t/ftemp/karlbad2.xml:2:26:cvc-enumeration-valid: 
Value 'insertx' is not facet-valid with respect to enumeration 
'[insert, update]'. It must be a value from the enumeration.
Error:file:///Users/admin/t/ftemp/karlbad2.xml:2:26:cvc-attribute.3: 
The value 'insertx' of attribute 'name' on element 'SharedDB' is not 
valid with respect to its type, 'simpleType_SharedDBQueries'.
Parse succeeded (0.146) with 2 errors and no warnings.
Saxon...
Validation error on line 2 column 26 of karlbad2.xml:
   FORG0001: Value "insertx" contravenes the enumeration facet 
"update, insert" of the type
   simpleType_SharedDBQueries (See 
http://www.w3.org/TR/xmlschema-1/#cvc-complex-type clause 3)
No validation errors
~/t/ftemp $


--
Contact us for world-wide XML consulting and instructor-led training
Free 5-hour video lecture: XSLT/XPath 1.0 & 2.0 http://ude.my/uoui9h
Crane Softwrights Ltd.            http://www.CraneSoftwrights.com/x/
G. Ken Holman                   mailto:gkholman@CraneSoftwrights.com
Google+ profile: https://plus.google.com/116832879756988317389/about
Legal business disclaimers:    http://www.CraneSoftwrights.com/legal
Received on Friday, 6 January 2012 02:58:35 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 6 January 2012 02:58:35 GMT