You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by John Snelson <jo...@oracle.com> on 2008/03/05 17:55:41 UTC

Problem with unique schema constraints

Hi everyone,

One of our users is having an issue with a unique constraint in his 
schema. I've attached an example XML document and XML Schema file. Both 
XML Spy and Visual Studio confirm that the XML document breaks the 
uniqueness constraint, but Xerces-C does not detect this. I've tested 
this and various permutations with both Xerces-C 2.8 and 3.0, and if 
anything 3.0 seems more broken:

1)
     <xs:unique name="vinUnique">
       <xs:selector xpath="ns:car"/>
       <xs:field xpath="@vin"/>
     </xs:unique>

Xerces-C 2.8: Valid
Xerces-C 3.0: Valid

2)
     <xs:unique name="vinUnique">
       <xs:selector xpath="*:car"/>
       <xs:field xpath="@vin"/>
     </xs:unique>

Xerces-C 2.8: Valid
Xerces-C 3.0: Valid

3)
     <xs:unique name="vinUnique">
       <xs:selector xpath="ns:car/@vin"/>
       <xs:field xpath="."/>
     </xs:unique>

Xerces-C 2.8: "Selectors cannot select attributes"
Xerces-C 3.0: "Selectors cannot select attributes"

4)
     <xs:unique name="vinUnique">
       <xs:selector xpath="*:car/@vin"/>
       <xs:field xpath="."/>
     </xs:unique>

Xerces-C 2.8: "Duplicate unique value declared"
Xerces-C 3.0: Valid

5)
     <xs:unique name="vinUnique">
       <xs:selector xpath="."/>
       <xs:field xpath="ns:car/@vin"/>
     </xs:unique>

Xerces-C 2.8: Valid
Xerces-C 3.0: Valid

6)
     <xs:unique name="vinUnique">
       <xs:selector xpath="."/>
       <xs:field xpath="*:car/@vin"/>
     </xs:unique>

Xerces-C 2.8: "Field matches more than one value within the scope of its 
selector" and "Duplicate unique value declared"
Xerces-C 3.0: Valid

As far as I can tell there seems to be at least two separate bugs here - 
namespaces in the XPath selector and field aren't handled correctly, and 
a separate problem with not checking unique constraints correctly.

Can anyone comment on what might be going on here?

John

-- 
John Snelson, Oracle Corporation            http://snelson.org.uk/john
Berkeley DB XML:        http://www.oracle.com/database/berkeley-db/xml
XQilla:                                  http://xqilla.sourceforge.net

Re: Problem with unique schema constraints

Posted by John Snelson <jo...@oracle.com>.
I found the xs:anySimpleType bug already reported, so I added my 
information to the bug report:

https://issues.apache.org/jira/browse/XERCESC-1393

The wildcard namespace issue has been reported here:

https://issues.apache.org/jira/browse/XERCESC-1787

John

David Bertoni wrote:
> Boris Kolpackov wrote:
>> Hi John,
>>
>> John Snelson <jo...@oracle.com> writes:
>>
>>> why doesn't the illegal syntax (*:car) give an error in Xerces-C
>>
>> I am not sure about this. Perhaps Xerces-C++ implements more than
>> is required by the spec (it should be quite easy to support the
>> namespace wildcards).
> Conforming implementations are not allowed to do "more than required by 
> the spec."  The XPath recommendation explicitly disallows using a 
> wildcard in the namespace portion of a QName.  (It had been allowed in 
> earlier drafts.)
> 
> I think we need to report this as an error.
> 
>>
>>
>>> and why don't the legal syntaxes (below) work?
>>
>> This has something to do with the fact that your vin attribute
>> is (implicitly) of xs:anySimpleType. If you make it of some
>> other type (e.g., int) then 3.0.0 detects duplication. Could
>> you please create a bug report and attach your schema and XML
>> files to it?
> You might as well mention that we need to tighten up the NameTest 
> checking as well.
> 
> Dave
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
> For additional commands, e-mail: c-dev-help@xerces.apache.org
> 


-- 
John Snelson, Oracle Corporation            http://snelson.org.uk/john
Berkeley DB XML:        http://www.oracle.com/database/berkeley-db/xml
XQilla:                                  http://xqilla.sourceforge.net

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


Re: Problem with unique schema constraints

Posted by David Bertoni <db...@apache.org>.
Boris Kolpackov wrote:
> Hi John,
> 
> John Snelson <jo...@oracle.com> writes:
> 
>> why doesn't the illegal syntax (*:car) give an error in Xerces-C
> 
> I am not sure about this. Perhaps Xerces-C++ implements more than
> is required by the spec (it should be quite easy to support the
> namespace wildcards).
Conforming implementations are not allowed to do "more than required by the 
spec."  The XPath recommendation explicitly disallows using a wildcard in 
the namespace portion of a QName.  (It had been allowed in earlier drafts.)

I think we need to report this as an error.

> 
> 
>> and why don't the legal syntaxes (below) work?
> 
> This has something to do with the fact that your vin attribute
> is (implicitly) of xs:anySimpleType. If you make it of some
> other type (e.g., int) then 3.0.0 detects duplication. Could
> you please create a bug report and attach your schema and XML
> files to it?
You might as well mention that we need to tighten up the NameTest checking 
as well.

Dave

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


Re: Problem with unique schema constraints

Posted by Boris Kolpackov <bo...@codesynthesis.com>.
Hi John,

John Snelson <jo...@oracle.com> writes:

> why doesn't the illegal syntax (*:car) give an error in Xerces-C

I am not sure about this. Perhaps Xerces-C++ implements more than
is required by the spec (it should be quite easy to support the
namespace wildcards).


> and why don't the legal syntaxes (below) work?

This has something to do with the fact that your vin attribute
is (implicitly) of xs:anySimpleType. If you make it of some
other type (e.g., int) then 3.0.0 detects duplication. Could
you please create a bug report and attach your schema and XML
files to it?

Thanks,
Boris

-- 
Boris Kolpackov, Code Synthesis Tools
Open source XML data binding for C++:   http://codesynthesis.com/products/xsd
Mobile/embedded validating XML parsing: http://codesynthesis.com/products/xsde

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


Re: Problem with unique schema constraints

Posted by John Snelson <jo...@oracle.com>.
Hi Dave,

Thanks for your analysis. So I guess I have two questions - why doesn't 
the illegal syntax (*:car) give an error in Xerces-C, and why don't the 
legal syntaxes (below) work?

David Bertoni wrote:
> John Snelson wrote:
>> 1)
>>     <xs:unique name="vinUnique">
>>       <xs:selector xpath="ns:car"/>
>>       <xs:field xpath="@vin"/>
>>     </xs:unique>
>>
>> Xerces-C 2.8: Valid
>> Xerces-C 3.0: Valid
>>
>> 5)
>>     <xs:unique name="vinUnique">
>>       <xs:selector xpath="."/>
>>       <xs:field xpath="ns:car/@vin"/>
>>     </xs:unique>
>>
>> Xerces-C 2.8: Valid
>> Xerces-C 3.0: Valid

I believe the example document I attached should fail both of these 
uniqueness constraints.

John

-- 
John Snelson, Oracle Corporation            http://snelson.org.uk/john
Berkeley DB XML:        http://www.oracle.com/database/berkeley-db/xml
XQilla:                                  http://xqilla.sourceforge.net

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


Re: Problem with unique schema constraints

Posted by David Bertoni <db...@apache.org>.
John Snelson wrote:
> Hi everyone,
> 
> One of our users is having an issue with a unique constraint in his 
> schema. I've attached an example XML document and XML Schema file. Both 
> XML Spy and Visual Studio confirm that the XML document breaks the 
> uniqueness constraint, but Xerces-C does not detect this. I've tested 
> this and various permutations with both Xerces-C 2.8 and 3.0, and if 
> anything 3.0 seems more broken:
> 
> 1)
>     <xs:unique name="vinUnique">
>       <xs:selector xpath="ns:car"/>
>       <xs:field xpath="@vin"/>
>     </xs:unique>
> 
> Xerces-C 2.8: Valid
> Xerces-C 3.0: Valid
> 
> 2)
>     <xs:unique name="vinUnique">
>       <xs:selector xpath="*:car"/>
>       <xs:field xpath="@vin"/>
>     </xs:unique>
This is an invalid expression according to the schema recommendation.  The 
namespace part of the QName is not allowed to be wildcard.  See: 
http://www.w3.org/TR/xmlschema-1/#NameTest

> 
> Xerces-C 2.8: Valid
> Xerces-C 3.0: Valid
> 
> 3)
>     <xs:unique name="vinUnique">
>       <xs:selector xpath="ns:car/@vin"/>
>       <xs:field xpath="."/>
>     </xs:unique>
> 
> Xerces-C 2.8: "Selectors cannot select attributes"
> Xerces-C 3.0: "Selectors cannot select attributes"
> 
> 4)
>     <xs:unique name="vinUnique">
>       <xs:selector xpath="*:car/@vin"/>
>       <xs:field xpath="."/>
>     </xs:unique>
Again, this is an invalid XPath expression.

> 
> Xerces-C 2.8: "Duplicate unique value declared"
> Xerces-C 3.0: Valid
> 
> 5)
>     <xs:unique name="vinUnique">
>       <xs:selector xpath="."/>
>       <xs:field xpath="ns:car/@vin"/>
>     </xs:unique>
> 
> Xerces-C 2.8: Valid
> Xerces-C 3.0: Valid
> 
> 6)
>     <xs:unique name="vinUnique">
>       <xs:selector xpath="."/>
>       <xs:field xpath="*:car/@vin"/>
>     </xs:unique>
Again, this is an invalid XPath expression.

Xerces-J reports the following:

V:\test\snelson>java sax.Writer -n -v -s foo.xml
<?xml version="1.0" encoding="UTF-8"?>
<cars xsi:schemaLocation="http://www.example.com/4.xsd foo.xsd">
   <car vin="1"></car>
   [Error] foo.xml:6:17: cvc-identity-constraint.4.1: Duplicate unique 
value [1]
declared for identity constraint "vinUnique" of element "cars".
<car vin="1"></car>
</cars>

Dave

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