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 Vadim Solonovich <vs...@park.ru> on 2001/04/11 15:35:51 UTC

How to apply unique constraint ?

Hello, All !  
I am trying to specify  that all elements of types derived from base must have an unique attribute within container element  in my schema .
I know there is ID type, which provides uniqueness. But the value of type ID must start with a character or '_'  that is not applicable for me. 
I am using Xerces-j 1.3.1 stable distribution  SAXCount sample with the following command line to validate the xml file : java sax.SAXCount -v data.xml. 
The following test passes without syntax errors, that should not happen.  What am I doing wrong ?

Thanks in advance,
    Vadim Solonovich

File test.xsd :

<?xml version='1.0' encoding='UTF-8'?>
<xsd:schema xmlns:xsd='http://www.w3.org/2000/10/XMLSchema'>

<xsd:complexType name="base" abstract="true">
   <xsd:attribute name="id" type="xsd:positiveInteger" use="required"/>
</xsd:complexType>
 
<xsd:complexType name="derived1">
   <xsd:complexContent>
       <xsd:extension base="base"/>
   </xsd:complexContent>
</xsd:complexType>
 
<xsd:complexType name="derived2">    
   <xsd:complexContent>
        <xsd:extension base="base"/>
    </xsd:complexContent>
</xsd:complexType>

<xsd:element name="container">
    <xsd:complexType>
        <xsd:sequence>
            <xsd:element name="variable-content" type="base" minOccurs='1' maxOccurs='unbounded'/>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:unique>
        <xsd:selector xpath="variable-content"/>
        <xsd:field xpath="id"/>
    </xsd:unique>
</xsd:element>

</xsd:schema>

File test.xml:

<?xml version="1.0" encoding="UTF-8"?>
<container xmlns:xsi='http://www.w3.org/2000/10/XMLSchema-instance'
        xsi:noNamespaceSchemaLocation='test.xsd'>
    
     <variable-content xsi:type="derived1" id="1"/>
     <variable-content xsi:type="derived1" id="1"/>
     <variable-content xsi:type="derived2" id="1"/>

</container>

Re: How to apply unique constraint ?

Posted by Вадим Солонович <vs...@park.ru>.
> Andy Clark wrote:
> > 1) The code doesn't correctly look for the schema keyword
> >    elements using the {URI,localpart} qualified name. Making
> 
> Checked in a fix for this. The other problem remains but it
> looks like it *will* verify the identity constraint with
> anonymous elements in the path. However, it will complain
> that it can't find the declaration for the anonymous element
> used in the path. Strange.
> 
> The identity constraint code really needs an update so it's
> probably not worth doing too much work on this right now.
> 

Dear Andy !
Where can i find this fix ? I've built the code for Xerces from cvs but it seems the fix is not there. Everything works exactly the same you have described in problem 1). Declaring elements used in xpath expression top-level does not help verify key/unique constraints.

Thanks,
    Vadim.

Re: How to apply unique constraint ?

Posted by Andy Clark <an...@apache.org>.
Andy Clark wrote:
> 1) The code doesn't correctly look for the schema keyword
>    elements using the {URI,localpart} qualified name. Making

Checked in a fix for this. The other problem remains but it
looks like it *will* verify the identity constraint with
anonymous elements in the path. However, it will complain
that it can't find the declaration for the anonymous element
used in the path. Strange.

The identity constraint code really needs an update so it's
probably not worth doing too much work on this right now.

-- 
Andy Clark * IBM, TRL - Japan * andyc@apache.org

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


Re: How to apply unique constraint ?

Posted by Andy Clark <an...@apache.org>.
Vadim Solonovich wrote:
> The following test passes without syntax errors, that should 
> not happen.  What am I doing wrong ?

Nothing. It's a bug. Actually it's a series of bugs. Here's
the ones that I discovered:

1) The code doesn't correctly look for the schema keyword
   elements using the {URI,localpart} qualified name. Making
   your Schema use the default namespace solved this problem
   but highlighted another.

2) The current code tries to verify that the elements in
   your paths are actually declared. If not, it will signal
   an error and your identity constraint will *not* be used.
   But the code that does this only looks at elements 
   declared top-level. This is a bug.

   The good news (or is this bad news?) is that the subset
   introduced in the Schema PR is ambiguous so we won't be
   able to do this check, anyway. If you declare all of
   your elements used in your XPath expressions at the top
   level and don't use anonymous types, then it'll work.

However, you do have one bug in your Schema. Your field
references the *element* called "id" when it's really an
*attribute* in your grammar. So change it to "@id", instead.
   
-- 
Andy Clark * IBM, TRL - Japan * andyc@apache.org

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