W3C home > Mailing lists > Public > xmlschema-dev@w3.org > December 2006

Re: Element Takes Enumerated List but has Attribute that Takes a String

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
Message-ID: <OF164BF5B2.2F1EBFFA-ON85257249.0052C32D-85257249.00535B6A@lotus.com>

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 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:14:56 GMT