XML schema for fixed element with fixed attribute?
What would be the proper XML Schema 1.0 declaration for
<notice xml:lang="en">Banana banana banana</notice>
Where:
- The xml: lang attribute is required.
- The value of "en" is fixed and required.
- The content of the notice is plain text.
- The content of the notification is fixed (as indicated above) and is required?
My best (but wrong) effort is the following snippet:
<xs:element name="notice" use="required" fixed="Banana banana banana"> <xs:complexType> <xs:simpleContent> <xs:extension> <xs:attribute ref="xml:lang" use="required" fixed="en"/> </xs:extension> </xs:simpleContent> </xs:complexType> </xs:element>
<?xml version="1.0" encoding="utf-8"?> <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:import namespace="http://www.w3.org/XML/1998/namespace" /> <xs:element name="notice" type="notice"/> <xs:complexType name="notice"> <xs:simpleContent> <xs:extension base="CONTENT"> <xs:attribute ref="xml:lang" use="required" fixed="en"/> </xs:extension> </xs:simpleContent> </xs:complexType> <xs:simpleType name="CONTENT"> <xs:restriction base="xs:string"> <xs:enumeration value="Banana banana banana"/> </xs:restriction> </xs:simpleType> </xs:schema>