W3C home > Mailing lists > Public > xmlschema-dev@w3.org > November 2003

Schema validation:

From: Srinivasan, Sriram <SSrinivasan@filenet.com>
Date: Mon, 3 Nov 2003 17:23:06 -0800
Message-ID: <2CFDD422D26CF442AB21AFFFCF33AEC3092799@hq-ex2kpo1.filenet.fn.com>
To: <xmlschema-dev@w3.org>

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

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 14:56:03 UTC