OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help



   Re: [xml-dev] XML schema type question

[ Lists Home | Date Index | Thread Index ]

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" />

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:restriction base="_fooType" />

Second, you can derive types that have simple content of a type of
your choice:

<xs:complexType name="_fooSimpleContentType" abstract="true">
    <xs:restriction base="_fooType">
        <xs:restriction base="_fooSimpleType" />

<xs:simpleType name="_fooSimpleType">

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...)



Jeni Tennison


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS