You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Stanimir Stamenkov <st...@myrealbox.com> on 2006/01/04 13:12:58 UTC

[XML Schema] Invalid constraint value error (bug?)

Using Xerces 2.7.1 I get an error loading the following schema:

<?xml version="1.0" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
   <xs:element name="sample-elem" type="MyInteger" default="0" />
   <xs:simpleType name="MyInteger">
     <xs:restriction base="xs:decimal">
       <xs:pattern value="[\-+]?[0-9]+" />
     </xs:restriction>
   </xs:simpleType>
</xs:schema>

And the error:

e-props-correct.2: Invalid value constraint value '0' in element 
'sample-elem'.

I don't see anything wrong with the schema and I've tried validating 
it using the XML Schema Validator [1] on the W3C site, which gave me 
no error. Am I missing something or it appears to be a problem with 
the Xerces implementation?

[1] http://www.w3.org/2001/03/webdata/xsv

-- 
Stanimir


---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: [XML Schema] Invalid constraint value error (bug?)

Posted by Sandy Gao <sa...@ca.ibm.com>.
> While the XML Schema Datatypes document has defined such canonical 
> lexical representation for the built-in types I haven't found a 
> place where it specifies how the canonical lexical representation 
> for a user defined datatype is determined or whether it has such one 
> (as with "MyInteger" in my case).

I think you've found a hole in the spec.

>From my experience working on Schema and as a member of the Schema working 
group, I believe the intention is that the value->canonical mapping is 
inherited if you derive a type from its base type. Or we can look at it 
from a different angle: the canonical mapping is specified on the "value", 
not the type. Because your own type's values are the same as those in the 
base type, the corresponding canonical mapping stays the same.

The only exception to this rule is the derivation between "decimal" and 
"integer" [1], where the canonical mapping changed: decimal point is not 
allowed in integer's lexical space (hence canonical values).

[1] http://www.w3.org/TR/xmlschema-2/#integer

Thanks,
Sandy Gao
XML Parser Development, IBM Canada
(1-905) 413-3255
sandygao@ca.ibm.com

Re: [XML Schema] Invalid constraint value error (bug?)

Posted by Stanimir Stamenkov <st...@myrealbox.com>.
/Peter McCracken/:

> I've looked into the issue, and I don't believe this is a bug; 
> this behaviour is required by the schema spec.  Looking at the 
> Element Declaration Properties Correct section of the Schema Spec 
> [1], point 2 states that the "canonical lexical representation" 
> of the default value must match the pattern, not just the 
> supplied lexical representation.
> 
> [1] http://www.w3.org/TR/xmlschema-1/#e-props-correct

I see the point but, still I'm missing: the "canonical lexical 
representation" [2]:

> [Definition:]  A canonical lexical representation is a set of 
> literals from among the valid set of literals for a datatype such 
> that there is a one-to-one mapping between literals in the canonical 
> lexical representation and values in the ·value space·.

While the XML Schema Datatypes document has defined such canonical 
lexical representation for the built-in types I haven't found a 
place where it specifies how the canonical lexical representation 
for a user defined datatype is determined or whether it has such one 
(as with "MyInteger" in my case). In this regard I'm still unclear 
whether Xerces makes over assumption, that the canonical lexical 
representation should match the one of the nearest built-in type the 
type has been derived from, but still I may be missing something?

[2] http://www.w3.org/TR/xmlschema-2/#dt-canonical-representation

-- 
Stanimir


---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: [XML Schema] Invalid constraint value error (bug?)

Posted by Stanimir Stamenkov <st...@myrealbox.com>.
/Peter McCracken/:

> So, although it 
> would make more sense to compare the original lexical value against the 
> pattern, the next best choice is to compare the canonical representation 
> of the actual value.

Does it makes sense for a pattern conflicting with the canonical 
representation to be invalid then? Although it conflicts only with a 
constraint value, if specified, and I'm not really sure how one 
could test for such conflict.

Or may be there should be a way to specify not to inherit the 
canonical representation and treat every lexical value as canonical 
value, which would probably "loose" any machine specific 
representation of the value, i.e. a 'decimal' being a number won't 
be natively number anymore, but just a string, for example.

-- 
Stanimir


---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: [XML Schema] Invalid constraint value error (bug?)

Posted by Peter McCracken <pe...@ca.ibm.com>.
Sandy has already responded to the list addressing the main issue of 
canonical representations, but I thought I'd come back to my previous post 
to clarify some things.

Peter McCracken/Toronto/IBM@IBMCA wrote on 01/04/2006 01:10:22 PM:

> For an instance document, the 
> canonical representation is used *only* if there is a "fixed" value 
> constraint [1] (Suppose the fixed value of an element is "0.00" and the 
> instance document specifies "0".  It makes sense to convert them both to 
a 
> canonical representation "0.0" before comparing them for equality).

> [1] http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/#cvc-elt (see 
> clause 5.2.2)

It seems I was wrong on this point.  The canonical representation of the 
value in the instance document is not used to compare against the fixed 
value constraint.  I took the wrong interpretation of clause 5.2.2.2.2 in 
the above reference [1] -- the true interpretation is that the actual 
values are compared, not the lexical representations.

> When parsing a schema, I'm not sure why the Schema spec requires that 
the 
> canonical value of default value constraints are valid.

The reason for this is because the schema component model for element (and 
attribute) declarations only keeps around the *actual* value in the {value 
constraint} property, and not the original lexical value that was used in 
the schema document [2].  (It's also possible that a schema component 
model was created in some way other than by reading a schema document, in 
which case there wouldn't be an original lexical value).  So, although it 
would make more sense to compare the original lexical value against the 
pattern, the next best choice is to compare the canonical representation 
of the actual value.

[2] 
http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/#Element_Declaration_details

Cheers,
-- 
Peter McCracken
XML Parser Development
IBM Toronto Lab
Phone: 905-413-5201 T/L 969-5201
Email: peterjm@ca.ibm.com

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: [XML Schema] Invalid constraint value error (bug?)

Posted by Peter McCracken <pe...@ca.ibm.com>.
Dick Deneer <di...@donkeydevelopment.com> wrote on 01/04/2006 
12:29:46 PM:

> But this is not consistent with the fact that an instance document with 
>   a "0" value is valid.

I agree that it seems strange that an instance document with "0" is valid 
but a default value of "0" is invalid, but once again it turns out that 
this is what the Schema Spec requires.  For an instance document, the 
canonical representation is used *only* if there is a "fixed" value 
constraint [1] (Suppose the fixed value of an element is "0.00" and the 
instance document specifies "0".  It makes sense to convert them both to a 
canonical representation "0.0" before comparing them for equality).  Thus, 
in response to the issue at hand, since we're not using a fixed value 
constraint, we're not using the canonical representation, and therefore 
"0" is a valid value of type MyInteger.

When parsing a schema, I'm not sure why the Schema spec requires that the 
canonical value of default value constraints are valid.  It does seem (to 
me) like this should only apply to fixed value constraints, as is done 
with instance documents.  Someone with more knowledge of schema than me 
might be able to answer this.  However, unless the Schema spec changes, 
the current behaviour of Xerces is technically correct, both when saying 
"0" is valid for instance documents and "0" is invalid for default values 
in schema documents.

[1] http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/#cvc-elt (see 
clause 5.2.2)

-- 
Peter McCracken
XML Parser Development
IBM Toronto Lab
Phone: 905-413-5201 T/L 969-5201
Email: peterjm@ca.ibm.com

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: [XML Schema] Invalid constraint value error (bug?)

Posted by Dick Deneer <di...@donkeydevelopment.com>.
Ok,

But this is not consistent with the fact that an instance document with  
  a "0" value is valid.

Dick Deneer
Peter McCracken heeft op woensdag, 4 jan 2006 om 17:32  
(Europe/Amsterdam) het volgende geschreven:

> Stanimir Stamenkov <st...@myrealbox.com> wrote on 01/04/2006 10:26:07  
> AM:
>
>>> Seems it is the combination of the pattern facet and the default
> value.
>>
>> FWIW, the same thing but using 'string' base doesn't cause problem:
>
> I've looked into the issue, and I don't believe this is a bug; this
> behaviour
> is required by the schema spec.  Looking at the Element Declaration
> Properties
> Correct section of the Schema Spec [1], point 2 states that the  
> "canonical
> lexical representation" of the default value must match the pattern,  
> not
> just
> the supplied lexical representation.
>
> The canonical lexical representation of the xs:decimal type requires  
> the
> decimal point and at least one digit after the decimal point [2].  In  
> the
> given
> example, the canonical lexical representation of "0" is "0.0", which of
> course
> does not match the required pattern for MyInteger in the schema, and  
> thus
> the
> schema is invalid.
>
> My suggestion would be to change the base type to xs:integer or  
> xs:string.
> If you're stuck using xs:decimal, you need to change your pattern to  
> allow
> "integers" with a zero after the decimal point, i.e.  
> "[\-+]?[0-9]+(\.0)?"
>
> [1] http://www.w3.org/TR/xmlschema-1/#e-props-correct
> [2]
> http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/ 
> datatypes.html#decimal
>
> -- 
> Peter McCracken
> XML Parser Development
> IBM Toronto Lab
> Phone: 905-413-5201 T/L 969-5201
> Email: peterjm@ca.ibm.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org
>
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: [XML Schema] Invalid constraint value error (bug?)

Posted by Peter McCracken <pe...@ca.ibm.com>.
Stanimir Stamenkov <st...@myrealbox.com> wrote on 01/04/2006 10:26:07 AM:

> > Seems it is the combination of the pattern facet and the default 
value.
> 
> FWIW, the same thing but using 'string' base doesn't cause problem:

I've looked into the issue, and I don't believe this is a bug; this 
behaviour
is required by the schema spec.  Looking at the Element Declaration 
Properties
Correct section of the Schema Spec [1], point 2 states that the "canonical
lexical representation" of the default value must match the pattern, not 
just
the supplied lexical representation.

The canonical lexical representation of the xs:decimal type requires the
decimal point and at least one digit after the decimal point [2].  In the 
given
example, the canonical lexical representation of "0" is "0.0", which of 
course
does not match the required pattern for MyInteger in the schema, and thus 
the
schema is invalid.

My suggestion would be to change the base type to xs:integer or xs:string.
If you're stuck using xs:decimal, you need to change your pattern to allow
"integers" with a zero after the decimal point, i.e. "[\-+]?[0-9]+(\.0)?"

[1] http://www.w3.org/TR/xmlschema-1/#e-props-correct
[2] 
http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/datatypes.html#decimal

-- 
Peter McCracken
XML Parser Development
IBM Toronto Lab
Phone: 905-413-5201 T/L 969-5201
Email: peterjm@ca.ibm.com

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: [XML Schema] Invalid constraint value error (bug?)

Posted by Stanimir Stamenkov <st...@myrealbox.com>.
/Stanimir Stamenkov/:

> Seems it is the combination of the pattern facet and the default value.

FWIW, the same thing but using 'string' base doesn't cause problem:

<?xml version="1.0" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
   <xs:element name="sample-elem" type="MyInteger" default="0" />
   <xs:simpleType name="MyInteger">
     <xs:restriction base="xs:string">
       <xs:pattern value="[\-+]?[0-9]+" />
     </xs:restriction>
   </xs:simpleType>
</xs:schema>

-- 
Stanimir


---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: [XML Schema] Invalid constraint value error (bug?)

Posted by Stanimir Stamenkov <st...@myrealbox.com>.
/dick.deneer@donkeydevelopment.com/:

>>    <xs:element name="sample-elem" type="MyInteger" default="0" />
>>    <xs:simpleType name="MyInteger">
>>      <xs:restriction base="xs:decimal">
>>        <xs:pattern value="[\-+]?[0-9]+" />
>>      </xs:restriction>
>>    </xs:simpleType>
>
> It seems the "default" attribute causes the problems. Maybe a 
> developer can confirm this bug?

Seems it is the combination of the pattern facet and the default 
value. If I remove the pattern facet I don't get error neither. Of 
course the "MyInteger" type is effectively the XML Schema "integer" 
type, but I get such constructs through a series of automated 
conversions between different grammar formats.

-- 
Stanimir


---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: [XML Schema] Invalid constraint value error (bug?)

Posted by di...@donkeydevelopment.com.
Stanimir,

I just checked your schema in XMLSpy and it gave no others. This is not a
absolute proof of a bug, because XMLSPY is not always to strict.
Using the latest Xerces builds I get the same error as you. But there is
one good point: when you check documents aginst the XSD , it validates
well. A value of zero (or others that are conforming the pattern) is
accepted. It seems the "default" attribute causes the problems. Maybe a
developer can confirm this bug?

Dick Deneer



> Using Xerces 2.7.1 I get an error loading the following schema:
>
> <?xml version="1.0" ?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
>    <xs:element name="sample-elem" type="MyInteger" default="0" />
>    <xs:simpleType name="MyInteger">
>      <xs:restriction base="xs:decimal">
>        <xs:pattern value="[\-+]?[0-9]+" />
>      </xs:restriction>
>    </xs:simpleType>
> </xs:schema>
>
> And the error:
>
> e-props-correct.2: Invalid value constraint value '0' in element
> 'sample-elem'.
>
> I don't see anything wrong with the schema and I've tried validating
> it using the XML Schema Validator [1] on the W3C site, which gave me
> no error. Am I missing something or it appears to be a problem with
> the Xerces implementation?
>
> [1] http://www.w3.org/2001/03/webdata/xsv
>
> --
> Stanimir
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org