Re: XML schema type question
Hi Jeff, > I've seen the XML Schema Type Library's "text" type, supporting > arbitrary mixed content. I have been unable to figure out how to > define a complex type whose contents are any simple type value or > any single element, but not a mixture, where an element of this > special type has a certain set of attributes That is, I'm trying to > define > > <element name="foo"> > <complexType > > ??? some kind of restriction of anyType with either simple or complex content > <restriction base="anyType"> > ??? > <attribute name="a" ...> > <attribute name="b" ...> > </restriction> > ??? > </complexType> > </element> > > so I can say in instance docs > > <fooList> > <foo a="x" b="y" xsi:type="xsd:boolean">true</foo> > <foo a="xx" b="yy" xsi:type="SomeComplexType"> > <someComplexType>...</someComplexType> > </foo> > ... > </fooList> I don't think that you can do precisely what you want, particularly because if you do xsi:type="xs:boolean" then you're saying "the foo element is (the simple type) xs:boolean", which isn't true because it has attributes. What you can do, I think, is as follows. Start off with a general complex type for your element which is *mixed* (allows both text and element content) and has the attributes that you want to be common to all your foo elements: <xs:element name="foo" type="_fooType" /> <xs:complexType name="_fooType" abstract="true" mixed="true"> <xs:attribute name="a" type="xs:string" /> <xs:attribute name="b" type="xs:string" /> </xs:complexType> You can then derive, by restriction, from that type in two ways. First, you can derive types that have complex content and *aren't* mixed (don't have textual content): <xs:complexType name="_fooComplexContentType" abstract="true"> <xs:complexContent> <xs:restriction base="_fooType" /> </xs:complexContent> </xs:complexType> Second, you can derive types that have simple content of a type of your choice: <xs:complexType name="_fooSimpleContentType" abstract="true"> <xs:simpleContent> <xs:restriction base="_fooType"> <xs:simpleType> <xs:restriction base="_fooSimpleType" /> </xs:simpleType> </xs:restriction> </xs:simpleContent> </xs:complexType> <xs:simpleType name="_fooSimpleType"> ... </xs:simpleType> Finally, you can derive the concrete types that you want to use in your instance from these types, by extension (to add element content to the empty _fooComplexContentType) or restriction (to specify the allowed values of the _fooSimpleType). (It's *so* much easier in RELAX NG...) Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format