[
Lists Home |
Date Index |
Thread Index
]
Thanks, Jeni. This seems a good approach. Your patient and thoughtful
responses on this list to various practical and theoretical questions are
greatly appreciated
I think one of the reasons this kind of thing is difficult is that there is
only a way to distinguish between the type of an element (including its
attributes and outside-the-angle-brackets content) and the type of the
content alone. If this were possible, then you would be able to say that in
general, the element foo supported attributes a and b, and allowed anyType
for content, and a particular instance element named foo had content of type
xsd:boolean. So along with xsi:type it would be nice to have
xsi:content-type.
What I wound up doing is cruder -- I used an no-attribute intermediate
element, as in
<complexType name="fooType">
<sequence>
<element name="value" type="anyType"/>
</sequence>
<attribute name="a" ...>
<attribute name="b" ...>
</complexType>
<element name="foo" type="fooType">
and in the instance
<foo a="x" b="y"><value xsi:type="xsd:boolean">true</value></foo>
<foo a="xx" b="yy">
<value xsi:type="someComplexType>
<someComplexElt>...</someComplexElt>
</value>
</foo>
Jeff
----- Original Message -----
From: "Jeni Tennison" <jeni@jenitennison.com>
To: "Jeff Greif" <jgreif@alumni.princeton.edu>
Cc: <xml-dev@lists.xml.org>
Sent: Friday, September 27, 2002 2:11 AM
Subject: Re: [xml-dev] 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/
>
>
> -----------------------------------------------------------------
> The xml-dev list is sponsored by XML.org <http://www.xml.org>, an
> initiative of OASIS <http://www.oasis-open.org>
>
> The list archives are at http://lists.xml.org/archives/xml-dev/
>
> To subscribe or unsubscribe from this list use the subscription
> manager: <http://lists.xml.org/ob/adm.pl>
>
>
>
|