\hypertarget{complexType}{}\subsection{complex\-Type}\label{complexType}
The only complex type predefined in XML schema is any\-Type, the default type for elements, and a super-class of any user-defined type. The nearest analogue is RDF Resource. User defined complex types correspond to OWL classes which may be anonymous, globally qualified by the target namespace, or locally named and defined in a default namespace. For complex types with mixed or simple content, we model these as restrictions on its RDF value.

Global, named complex types are defined in the target namespace. The following schema defines a complex type, $<$\href{http://example.org/Foo}{\tt http://example.org/Foo}$>$.



\begin{DocInclude}\begin{verbatim}<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://example.org/" >
        <xs:complexType name="Foo" />
</xs:schema>
\end{verbatim}
\end{DocInclude}
 

\begin{DocInclude}\begin{verbatim}# Base: http://example.org/complexType1.owl
@prefix ns1:     <http://example.org/def/> .
@prefix xs:      <http://www.w3.org/2001/XMLSchema> .
@prefix ns2:     <http://example.org/> .
@prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
@prefix daml:    <http://www.daml.org/2001/03/daml+oil#> .
@prefix rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xs_:     <http://www.w3.org/2001/XMLSchema#> .
@prefix :        <#> .
@prefix owl:     <http://www.w3.org/2002/07/owl#> .

<>    a       owl:Ontology .

ns2:Foo
      a       owl:Class .
\end{verbatim}
\end{DocInclude}


If the target namespace ends with an alpha-numeric, a fragment separator '\#' is introduced.

For locally defined elements we derive value (OWL all\-Values\-From) restrictions from their type. A complex type defines a content model (particle) for element content. For global elements the type is set by the property range. The Russian Doll style of schema mirrors the structure of the XML instance document. Short on references to global definitions, we see attributes \& elements defined in-situ (locally), where names are easily recycled. We might foresee a problem with different appearances of an element within the particle having different types. However, the Element Declarations Consistent constraint limits elements within the same particle to be of the same type. This permits us to construct an all\-Values\-From restriction based only on the first appearance of an element within a particle.

This example also shows the definition of a property range based on an anonymous complex type. It also shows how simple content is captured in the form of an rdf:value. In this case the element value can appear at most once. If the element is empty the value isn't added.



\begin{DocInclude}\begin{verbatim}<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://example.org/" >
        <xs:element name="foo">
                <xs:complexType>
                        <xs:simpleContent>
                                <xs:restriction base="xs:string"/>
                        </xs:simpleContent>
                </xs:complexType>
        </xs:element>
</xs:schema>
\end{verbatim}
\end{DocInclude}
 

\begin{DocInclude}\begin{verbatim}# Base: http://example.org/complexType2.owl
@prefix ns1:     <http://example.org/def/> .
@prefix xs:      <http://www.w3.org/2001/XMLSchema> .
@prefix ns2:     <http://example.org/> .
@prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
@prefix daml:    <http://www.daml.org/2001/03/daml+oil#> .
@prefix rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xs_:     <http://www.w3.org/2001/XMLSchema#> .
@prefix :        <#> .
@prefix owl:     <http://www.w3.org/2002/07/owl#> .

rdf:value
      a       owl:DatatypeProperty , rdf:Property .

<>    a       owl:Ontology .

ns2:foo
      a       owl:ObjectProperty ;
      rdfs:range
              [ a       owl:Class ;
                rdfs:subClassOf
                        [ a       owl:Restriction ;
                          owl:cardinality "1"^^xs_:int ;
                          owl:onProperty rdf:value
                        ] ;
                rdfs:subClassOf
                        [ a       owl:Restriction ;
                          owl:allValuesFrom xs_:string ;
                          owl:onProperty rdf:value
                        ]
              ] .
\end{verbatim}
\end{DocInclude}


Instances of this in both XML and RDF are as follows:



\begin{DocInclude}\begin{verbatim}<?xml version="1.0" encoding="UTF-8"?>
<foo xmlns="http://example.org/">foobar</foo>
\end{verbatim}
\end{DocInclude}
 

\begin{DocInclude}\begin{verbatim}# Base: http://example.org/complexType2.xml
@prefix ns1:     <http://example.org/def/> .
@prefix xs:      <http://www.w3.org/2001/XMLSchema> .
@prefix ns2:     <http://example.org/> .
@prefix rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xs_:     <http://www.w3.org/2001/XMLSchema#> .
@prefix :        <#> .

<>    ns2:foo [ rdf:value "foobar"^^xs_:string
              ] .
\end{verbatim}
\end{DocInclude}


We may add attributes to a complex type either directly as in the example below (or as part of an attribute group), or within nested restrictions or extensions.



\begin{DocInclude}\begin{verbatim}<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://example.org/" >
        <xs:complexType name="Foo">
                <xs:attribute name="bar" type="xs:string" />
        </xs:complexType>
</xs:schema>
\end{verbatim}
\end{DocInclude}


The attribute 'bar' is unqualified, so the corresponding property is defined in the default namespace (xmlns=http://example.org/def/).



\begin{DocInclude}\begin{verbatim}# Base: http://example.org/complexType3.owl
@prefix ns1:     <http://example.org/def/> .
@prefix xs:      <http://www.w3.org/2001/XMLSchema> .
@prefix ns2:     <http://example.org/> .
@prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
@prefix daml:    <http://www.daml.org/2001/03/daml+oil#> .
@prefix rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xs_:     <http://www.w3.org/2001/XMLSchema#> .
@prefix :        <#> .
@prefix owl:     <http://www.w3.org/2002/07/owl#> .

ns1:bar
      a       owl:DatatypeProperty , rdf:Property .

<>    a       owl:Ontology .

ns2:Foo
      a       owl:Class ;
      rdfs:subClassOf
              [ a       owl:Restriction ;
                owl:maxCardinality "1"^^xs_:int ;
                owl:onProperty ns1:bar
              ] ;
      rdfs:subClassOf
              [ a       owl:Restriction ;
                owl:allValuesFrom xs_:string ;
                owl:onProperty ns1:bar
              ] .
\end{verbatim}
\end{DocInclude}


We can add structured content to a complex type, using the compositors, 'all', 'choice', 'sequence', and sometimes 'group'. These don't add any nested structure to the class itself but are used to determine the cardinalities of any added properties.\hypertarget{complextype_complexTypeChildren}{}\subsubsection{Child components}\label{complextype_complexTypeChildren}
\begin{itemize}
\item \hyperlink{simplecontent}{simple\-Content}\item \hyperlink{complexcontent}{complex\-Content}\item \hyperlink{group}{group}\item \hyperlink{all}{all}\item \hyperlink{choice}{choice}\item \hyperlink{sequence}{sequence}\item \hyperlink{attribute}{attribute}\item \hyperlink{attributegroup}{attribute\-Group}\item \hyperlink{anyattribute}{any\-Attribute}\item \hyperlink{annotation}{annotation} \end{itemize}
