[Home] [By Thread] [By Date] [Recent Entries]

  • To: xml-dev@l...
  • Subject: trying to do XML Schema validation with Xerces-J 2.4.0, does not complain about unique constraits when using the xs:key feature
  • From: Bill Riegel <BRiegel@l...>
  • Date: Wed, 14 May 2003 08:59:17 -0500

I can get it to complain about structural error's. i.e. have a child element
in the instance document but not defined in the XML Schema. 

But when I try to create in in-valid key constraint, i.e.
DataSet/WellEntireData/WellEntire/wellid is not unique, it does not throw an
exception. ( Note: xmlspy does ) 

Instance document:

<?xml version="1.0"?>

<DataSet xmlns=http://www.lgc.com/schema/OpenWorksData/2003
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
   xsi:schemaLocation="http://www.lgc.com/schema/OpenWorksData/2003
            Adt_OW_Stratigraphy2_Schema.xsd">
  <WellEntireData>
    <WellEntire>
      <wellid>3567</wellid>
    </WellEntire>
    <WellEntire>
      <wellid>3197</wellid>
    </WellEntire>
    <WellEntire>
      <wellid>3198</wellid>
     </WellEntire>
    <WellEntire>
      <wellid>3567</wellid>
    </WellEntire>
 </WellEntireData>
</DataSet>


XML Schema file.
 
<?xml version="1.0"?>
<xs:schema targetNamespace="http://www.lgc.com/schema/OpenWorksData/2003"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.lgc.com/schema/OpenWorksData/2003"
elementFormDefault="qualified" attributeFormDefault="unqualified">
  <!--This XML Schema defines an ADT XML File. It Defines the DataModel
OpenWorksData and partitionName Stratigraphy2-->
  <xs:element name="DataSet">
    <xs:complexType>
      <xs:all>
        <xs:element name="WellEntireData" type="WellEntireData_Type"
minOccurs="0">
          <xs:key name="WellEntire_InHierarchy_Key_Definition">
            <xs:selector xpath="WellEntire"/>
            <xs:field xpath="wellid"/>
          </xs:key>
        </xs:element>
      </xs:all>
    </xs:complexType>
  </xs:element>
   <xs:complexType name="WellEntireData_Type">
    <xs:sequence>
      <xs:group ref="WellEntire_Top_Group" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>
  <xs:group name="WellEntire_Top_Group">
    <xs:choice>
      <xs:element name="WellEntire" type="WellEntire_Type"/>
    </xs:choice>
  </xs:group>
  <xs:complexType name="WellEntire_Type">
    <xs:sequence>
      <xs:group ref="WellEntire_Atrributes_Group"/>
    </xs:sequence>
  </xs:complexType>
  <xs:group name="WellEntire_Atrributes_Group">
    <xs:sequence>
      <xs:element name="wellid" type="xs:integer"/>
     </xs:sequence>
  </xs:group>
  <xs:complexType name="WellEntireRef_Type">
    <xs:sequence>
      <xs:element name="wellid" type="xs:integer"/>
    </xs:sequence>
  </xs:complexType>
</xs:schema>

I have set the following features:

 
parser.getXMLReader().setFeature("http://apache.org/xml/features/validation/
dynamic", true );
 
parser.getXMLReader().setFeature("http://apache.org/xml/features/validation/
schema", true );

parser.getXMLReader().setFeature("http://apache.org/xml/features/validation/
schema-full-checking", true );
 
parser.getXMLReader().setFeature("http://xml.org/sax/features/validation",
true );
        

Am I setting the features incorrectly ?
Does the 2.4.0 version of Xerces support this feature of XML Schema ?



Bill Riegel
LandMark Graphics
713-839-3388



Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member