Re: complexType derivation method

Hi,

boriero wrote:

>      Can I create a new complexType with a simpleContent by
>      restricting or extending a basetype which is itself derived by
>      restriction or extension ?
>
In short, Yes. But it's important to remember that a complexType with
simpleContent can only be derived from either complexTypes _that
themselves_ have simpleContent (by restriction or extension) or
simpleTypes (by extension). See [1].

> <xs:complexType name="1" mixed="true">

>    <xs:simpleContent>
>         <xs:extension base="xs:string">
>             <xs:attribute name="x" type="xs:integer"/>
>         </xs:extension>
>     </xs:simpleContent>
> </xs:complexType>

This is not correct. In XSD you can't specify a type for the text
content in mixed content model. By specifying the simpleContent child
element you restrict the type to have text content only which doesn't
make sence for a mixed content model. So, in order to create a mixed
type it must have complexContent.

> <xs:complexType name="2">
>     <xs:simpleContent>
>         <xs:extension base="1">
>             <xs:attribute name="b" type="xs:string"/>
>         </xs:extension>
>     </xs:simpleContent>
> </xs:complexType>

Appart from the mixed="true" in type 1 this should work fine.

> <xs:complexType name="3>
>     <xs:simpleContent>
>         <xs:restriction base="1">
>             <xs:minLength value="2"/>
>         </xs:restriction>
>     </xs:simpleContent>
> </xs:complexType>

As I read the spec this should also be valid although none of the
validators I tested with could validate this type correctly.

>     2.    when i create a new complexType with a complexContent , can
> i restrict a base type removing one or more child elements?
>
> Yes, as long as the elements you want to remove are optional in the
> base type. The basic rule is (as written in the Primer):
> "...an application prepared for the values of the base type would not
> be surprised by the values of the restricted type."
> See comments below.
>  <xs:complexType name="Com">
>     <xs:sequence>
>         <xs:element name="B" type="xs:string"/>
>         <xs:element name="C" type="xs:integer"/>
>         <xs:element name="D" type="xs:string" maxOccurs="unbounded"/>
>     </xs:sequence>
> </xs:complexType>
> <xs:complexType name="Comrestr">

>    <xs:complexContent>

>         <xs:restriction base="Com">
>             <xs:sequence>
>                 <xs:element name="B" type="xs:string"/>
>                 <xs:element name="C" type="xs:integer"/>
>             </xs:sequence>
>         </xs:restriction>
>     </xs:complexContent>
> </xs:complexType>

This restriction is invalid because the element you try to remove (D) is
in fact required in the base type. To make this work you have to make
the D element optional in the base type by changing the declaration:
<xs:element name="D" type="xs:string" minOccurs="0"
maxOccurs="unbounded"/>

>     3.    May someone explain to me,even by an example, the use and
> meaning of <simpleType> as a child of a
> <simpleContent>...<restriction> ?
> <xs:complexType name="...">
>     <xs:simpleContent>
>         <xs:restriction base="..." >
>             <xs:simpleType name="...">

This is not valid as you have written it. The reason being that you
can't declare a named simpleType that isn't a direct child of the
xs:schema element. Written like this:

<xs:complexType name="...">
   <xs:simpleContent>
      <xs:restriction base="..." >
         <xs:simpleType>
            <xs:restriction base="xs:integer"/>

It could be used to restrict the text content of a previously defined
complexType. However, there is a contradiction in the spec regarding
this issue, see Henry's mail earlier [2].

[1] http://www.w3.org/TR/xmlschema-1/#declare-type (in the table with
heading: Complex Type Definition with simple content Schema Component)

[2] http://lists.w3.org/Archives/Public/xmlschema-dev/2002Jan/0063.html

Received on Wednesday, 9 January 2002 18:40:33 UTC