patrik.nyman
Usenet Archive
- Joined
- Dec 13, 2006
- Messages
- 27
- Reaction score
- 0
I'm wondering if this can be done within an XMLSchema:
I want to define an element <identifier> as having an attribute "type" with one of a given list of values. Based on what value is chosen, I want the *content* of the element to be restricted to following a certain pattern or being of a certain type.
For example, <identifier type="uri"> must contain something on the pattern "[a-z:]+[\d-]", while the content of <foo type="isbn"> must follow the pattern "[\d-]+".
The code I have is
<xs:element name="identifier">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attributeGroup ref="kb:att.identifier.type"/> </xs:extension> </xs:simpleContent> </xs:complexType> </xs:element>
<xs:attributeGroup name="att.identifier.type">
<xs:attribute name="type" use="required">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:enumeration value="issn"/>
<xs:enumeration value="isbn"/>
<xs:enumeration value="uri"/>
<xs:enumeration value="internal"/>
<xs:enumeration value="iso639-1"/>
<xs:enumeration value="iso639-2"/>
<xs:enumeration value="iso3166-1"/>
<xs:enumeration value="pmid"/>
<xs:enumeration value="keyTitle"/>
<xs:enumeration value="patentNumber"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:attributeGroup>
I want to define an element <identifier> as having an attribute "type" with one of a given list of values. Based on what value is chosen, I want the *content* of the element to be restricted to following a certain pattern or being of a certain type.
For example, <identifier type="uri"> must contain something on the pattern "[a-z:]+[\d-]", while the content of <foo type="isbn"> must follow the pattern "[\d-]+".
The code I have is
<xs:element name="identifier">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attributeGroup ref="kb:att.identifier.type"/> </xs:extension> </xs:simpleContent> </xs:complexType> </xs:element>
<xs:attributeGroup name="att.identifier.type">
<xs:attribute name="type" use="required">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:enumeration value="issn"/>
<xs:enumeration value="isbn"/>
<xs:enumeration value="uri"/>
<xs:enumeration value="internal"/>
<xs:enumeration value="iso639-1"/>
<xs:enumeration value="iso639-2"/>
<xs:enumeration value="iso3166-1"/>
<xs:enumeration value="pmid"/>
<xs:enumeration value="keyTitle"/>
<xs:enumeration value="patentNumber"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:attributeGroup>