I am trying to create an XSD for validating an XML file, and several elements need to have attributes but no text.
E.g. This should be considered valid:
<DEPRECATED value="blah"/>
These are invalid:
<DEPRECATED>blah</DEPRECATED>
<DEPRECATED value="blah">bad text</DEPRECATED>
I tried declaring a complex empty element as described here, but either I'm interpreting the example incorrectly or the example itself is wrong (see error below):
<xs:element name="DEPRECATED" type="stringValue" minOccurs="0" maxOccurs="1"/>
<xs:complexType name="stringValue">
<xs:complexContent>
<xs:restriction base="xs:integer">
<xs:attribute name="value" type="xs:string"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
Error: Complex Type Definition Representation Error for type 'stringValue'. When is used, the base type must be a complexType. 'integer' is a simpleType.
I also tried defining the complexType this way:
<xs:complexType name="stringValue">
<xs:attribute name="value" type="xs:string"/>
</xs:complexType>
But that considers the invalid examples above as valid. [EDIT: Correction, the above does work.]
I've also played around with the answers to similar questions (Define an XML element that must be empty and has no attributes, Prevent Empty Elements in XML via XSD) but no luck.
How do I validate that an element has attributes, but NO text?