Jump to content

Requiring attributes on empty elements


evanc

Recommended Posts

I have seen a couple other posts similar to this, but not quite the same… I am trying to create Schemas to validate my product's object model. I am finding many instances where attributes associated with elements depend upon the content of the element. For example:

<busy nil="true"></busy>

or

<busy type="boolean">true</busy>

are valid values. I have been using my own type with a union and optional attributes to validate this element like so:

<?xml version="1.0" encoding="UTF-8"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">  <xs:element name="busy">	<xs:complexType>	  <xs:simpleContent>		<xs:extension base="nilBoolean">		  <xs:attribute name="type" use="optional" type="xs:NCName"/>		  <xs:attribute name="nil" use="optional" type="xs:boolean"/>		</xs:extension>	  </xs:simpleContent>	</xs:complexType>  </xs:element>   <xs:simpleType name="nilBoolean">	<xs:union memberTypes="xs:boolean empty"/>  </xs:simpleType>  <xs:simpleType name="empty">	<xs:restriction base="xs:string">	  <xs:maxLength value="0"/>	</xs:restriction>  </xs:simpleType></xs:schema>

But what I would really like is to have more explicit control to say that the 'nil' attribute is required if the value is empty, and the 'type' attribute is required if the value is not empty. It sounds simple enough, but I haven't determined how. Can anyone point me on the correct path? Thanks,Evan

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...