Schema validation:

I have the following xml:
<StepParameters>
  <Parameter Name="testScriptParam2" Type="Boolean" Value="true"/>
  <Parameter Name="testScriptParam3" Type="String[]">
     <Values>
	  <Value Type="String">Q1</Value>
	  <Value Type="String">Q2</Value>
     </Values>
  </Parameter>
<StepParameters>

So a parameter element can contain either a Value attribute or if the
parameter is an array then it could contain a Values element which
inturn contain Value elements.

I have to validate the xml so that a Parameter element can have either a
Value attribute or a Values element, not both and atleast one of them.
Is there a way to specify it in xml schema. 
My current schema is defined like this. This seems to validate fine with
xmlspy version 2004 rel2. but using the latest xerces parser, the
validation fails saying:

org.xml.sax.SAXParseException: cvc-id.3: A field of identity constraint
'StepParameterValueKey' matched element 'Values', but this element does
not have a simple type.


<xs:complexType name="StepParametersType">
  <xs:sequence>
    <xs:element name="Parameter" type="ParameterType"
maxOccurs="unbounded">
      <xs:key name="StepParameterValueKey">
	  <xs:selector xpath="."/>
	  <xs:field xpath="Values|@Value"/>
	</xs:key>
    </xs:element>
  </xs:sequence>
</xs:complexType>


<xs:complexType name="ParameterType">
  <xs:sequence minOccurs="0" maxOccurs="unbounded">
    <xs:element name="Values" type="ValuesType"/>
  </xs:sequence >		
  <xs:attribute name="Name" type="xs:string" use="required"/>
  <xs:attribute name="Type" default="String">
  <xs:simpleType>
	<xs:restriction base="xs:string">
	  <xs:enumeration value="Boolean"/>
	  <xs:enumeration value="Integer"/>
	  <xs:enumeration value="Double"/>
	  <xs:enumeration value="Date"/>
	  <xs:enumeration value="String"/>
	  <xs:enumeration value="Boolean[]"/>
	  <xs:enumeration value="Integer[]"/>
	  <xs:enumeration value="Double[]"/>
	  <xs:enumeration value="Date[]"/>
	  <xs:enumeration value="String[]"/>
	  <xs:enumeration value="Object[]"/>
	  <xs:enumeration value="Parameter[]"/>
	  <xs:enumeration value="Parameters[]"/>
	</xs:restriction>
    </xs:simpleType>
  </xs:attribute>
  <xs:attribute name="Value" type="xs:string"/>
</xs:complexType>

<xs:complexType name="ValuesType">
  <xs:sequence>
    <xs:element name="Value" type="ValueType" maxOccurs="unbounded"/>
  </xs:sequence>
</xs:complexType>

<xs:complexType name="ValueType" mixed="true">
  <xs:choice minOccurs="0" maxOccurs="unbounded">
	<xs:element name="Parameter" type="ParameterType"/>
  </xs:choice>
  <xs:attribute name="Type" default="String">
    <xs:simpleType>
      <xs:restriction base="xs:NMTOKEN">
	  <xs:enumeration value="Boolean"/>
	  <xs:enumeration value="Date"/>
	  <xs:enumeration value="Double"/>
	  <xs:enumeration value="Integer"/>
	  <xs:enumeration value="Parameter"/>
	  <xs:enumeration value="Parameters"/>
	  <xs:enumeration value="String"/>
	</xs:restriction>
    </xs:simpleType>
  </xs:attribute>
</xs:complexType>

Received on Monday, 3 November 2003 20:26:28 UTC