Hi

I have the following xml which I want to validate:

there are 3 elements 
1. message - the root element
2. a string element - contains character content
3. a dictionary element - contains any number of string or dictionary
elements in any sequence
there is one constraint, the immediate children of a dictionary or message
element must have a unique "key" attribute

<?xml version="1.0"?>
<message xmlns="http://www.rubico.com/xml/schemas/dictionary-2.0";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
        <string key="hello1">some stuff</string>
        <string key="hello2">2000-01-01</string>
        <string key="hello3">some other stuff</string>
        <dictionary key="bob">
                <string key="hello1">some other stuff</string>          
                <string key="hello2">some other stuff</string>          
                <dictionary key="bob">
                        <string key="hello1">some other stuff</string>

                        <string key="hello2">some other stuff</string>

                </dictionary>
        </dictionary>   
</message>

Here is my schema

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"; 
xmlns="http://www.rubico.com/xml/schemas/dictionary-2.0";
targetNamespace="http://www.rubico.com/xml/schemas/dictionary-2.0";
elementFormDefault="qualified">

<xsd:element name="message">
     <xsd:complexType>
        <xsd:sequence>
                <xsd:group ref="dictionaryContent" minOccurs="0"
maxOccurs="unbounded"/>         
        </xsd:sequence> 
     </xsd:complexType>
     <xsd:unique name="uniqueKey1">
        <xsd:selector xpath="./string | ./dictionary"/>
        <xsd:field xpath="@key"/>
     </xsd:unique>     
</xsd:element>

<xsd:group name="dictionaryContent">
        <xsd:choice>
                <xsd:element name="string" type="stringType" nillable="true"
minOccurs="0" maxOccurs="1"/>
                <xsd:element name="dictionary" type="dictionaryType"
minOccurs="0" maxOccurs="1">
                        <xsd:unique name="uniqueKey">
                                <xsd:selector xpath="./string |
./dictionary"/>
                                <xsd:field xpath="@key"/>
                        </xsd:unique>    
                </xsd:element>
        </xsd:choice>
</xsd:group>

<xsd:complexType name="dictionaryType">
        <xsd:sequence>
                <xsd:group ref="dictionaryContent" minOccurs="0"
maxOccurs="unbounded"/>         
        </xsd:sequence> 
        <xsd:attribute name="key" type="xsd:string" use="required"/>    
</xsd:complexType>

<xsd:complexType name="stringType">
        <xsd:simpleContent>
        <xsd:extension base="xsd:string">
                <xsd:attribute name="key" type="xsd:string" use="required"/>

        </xsd:extension>        
        </xsd:simpleContent>
</xsd:complexType>

</xsd:schema>

I am getting errors when validating using xerces 1.4.3

[Error] dictionary2.xml:10:25: Duplicate unique value [ID Value:  hello1]
declared for identity constraint of element "dictionary".
[Error] dictionary2.xml:11:25: Duplicate unique value [ID Value:  hello2]
declared for identity constraint of element "dictionary".
java.lang.NullPointerException
        at
org.apache.xerces.validators.common.XMLValidator$ValueStoreBase.append(XMLVa
lidator.java:4751)
        at
org.apache.xerces.validators.common.XMLValidator$ValueStoreCache.transplant(
XMLValidator.java:5335)
        at
org.apache.xerces.validators.common.XMLValidator.callEndElement(XMLValidator
.java:1459)
        at
org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(XM
LDocumentScanner.java:1204)
        at
org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.
java:381)
        at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1081)
        at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1122)
        at sax.SAXCount.print(SAXCount.java:160)
        at sax.SAXCount.main(SAXCount.java:394)

As far as I can see, the "unique" constraint for the message element is
doing what I want(since there is only one... i.e key="bob" occurs twice but
not for the same element type), but the dictionary element does not. Without
going into the code (java newbie) it would appear the the unique constraint
for dictionary is only defined in one place, and all of the <field> values
are checked against this one list. Is this correct behaviour? I am not sure
why there is a NullPointerException, possibly this is bug?

Thanks
Colin
 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to