views:

16

answers:

0

I am making an XML schema for an XML document* and I am getting stuck on something which seems like it should be relatively simple to do. Take the following XML snippet:

 <some_element value="Yes" type="boolean">1</some_element >

In this case, I want to restrict the content of some_element to boolean values (xs:boolean) and I want to ensure that the element has a value attribute of [Yes, No] and a type attribute of boolean. I've figured out how to restrict the attributes, but not the content. Here's what I've come up with:

 <xs:element name="some_element">
      <xs:complexType mixed="true">
           <xs:attribute name="value" type="yesNoStringType" use="required"/>
           <xs:attribute name="type" fixed="boolean" use="required"/>
      </xs:complexType>
 </xs:element>
 <xs:simpleType name="yesNoStringType">
      <xs:restriction base="xs:string">
           <xs:enumeration value="Yes"/>
           <xs:enumeration value="No"/>
      </xs:restriction>
 </xs:simpleType>

Separately, is it possible to have an attribute that is conditional on the content of the element? For instance:

 <another_element nil="true"/>

Ideally, nil would only be required when the content of the element was empty -- otherwise it's not necessary.

*this XML document is designed to be easily slurped up by Rails' Hash.from_xml()