- From: <noah_mendelsohn@us.ibm.com>
- Date: Tue, 19 Dec 2006 10:10:27 -0500
- To: "Fortuno, Adam" <Adam_Fortuno@ghrsystems.com>
- Cc: xmlschema-dev@w3.org
I think you want something closer to:
<xs:simpleType name="CodeType">
<xs:restriction base="xs:token">
<xs:enumeration
value="ABC" />
<xs:enumeration
value="123" />
<xs:enumeration
value="DEF" />
</xs:restriction>
</xs:simpleType>
<xs:complexType name="FooType>
<xs:simpleContent>
<xs:extension base="CodeType">
<xs:attribute name="_Code"
type="xs:string"/>
</xs:extension>
<xs:simpleContent>
</xs:complexType>
<xs:element name="Foo" type="FooType"/>
Explanation:
Simple types define string-like content. In this case, you are defining a
new one for the CodeType that will be used to constrain the string-like
content of the element character children. The type of the element itself
is complex, because it has attributes too. We're defining FooType for
that. It states that it has simple (I.e. string-like) content, but is
extended to allow an attribute. The attribute _Code is of type xs:string.
I haven't run this through a validator, but I think it's either right or a
few typos away. Obviously, you could flip this around to have codes in
the attribute and string in the element by doing:
<xs:simpleType name="CodeType">
<xs:restriction base="xs:token">
<xs:enumeration
value="ABC" />
<xs:enumeration
value="123" />
<xs:enumeration
value="DEF" />
</xs:restriction>
</xs:simpleType>
<xs:complexType name="FooType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="_Code"
type="CodeType"/>
</xs:extension>
<xs:simpleContent>
</xs:complexType>
<xs:element name="Foo" type="FooType"/>
Good luck!
Noah
--------------------------------------
Noah Mendelsohn
IBM Corporation
One Rogers Street
Cambridge, MA 02142
1-617-693-4036
--------------------------------------
Received on Tuesday, 19 December 2006 15:11:04 UTC