[XMLSCHEMA-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

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>
Re: Element Takes Enumerated List but has Attribute that Takes a String

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

Subscribe to the Stylus Scoop newsletter for helpful XML tips and tutorials.
Email
First Name
Last Name
Company

Download Stylus Studio 6 XML Enterprise Edition

Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.