문제

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.

도움이 되었습니까?

해결책

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="..">)?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top