Question

My XML document looks like:

<Entries>
  <entry key="some string" value="some string"/>
  " "
  " "
  " "
</Entreis>

I need to enforce a rule that one of the entry elements must have a key of value "Version". What would the schema look like?

I tried

<xs:element name ="Entries">
  <xs:complexType>
    <xs:sequence minOccurs="1" maxOccurs="1">
      <xs:element name="entry">
        <xs:attribute name="key" fixed="Version" type="xs:string/>
        <xs:attribute name="value" type="xs:string/>
      </xs:element>
    </xs:sequence>
    <xs:sequence minOccurs="0" maxOccurs="unbounded">
      <xs:element name="entry">
        <xs:attribute name="key" type="xs:string/>
        <xs:attribute name="value" type="xs:string/>
      </xs:element>
    </xs:sequence>
  </xs:complexType>
 </xs:element>

but I get a validation error saying that I cannot have sequence appear twice in a complex type or that it is invalid or misplaced.

Was it helpful?

Solution

I'm afraid it cannot be done in xsd 1.0. You cannot have two elements with the same name but different (although similiar) structure at one place.

On the other side - what should @key="Version" express? Couldn't be this information presented as a part of Entries element (somthing like <Entries version="..">)?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top