[xsd-users] Specifying Element content for "anyType" Elements

Boris Kolpackov boris at codesynthesis.com
Wed Sep 10 05:05:29 EDT 2008


Hi Jan,

Jan Klimke <jan.klimke at hpi.uni-potsdam.de> writes:

> I need an instance of the following "PropertyName"-element:
> 
> <xsd:element name="PropertyName" type="ogc:PropertyNameType"
> substitutionGroup="ogc:expression"/>
> 
> <xsd:complexType name="PropertyNameType">
>       <xsd:complexContent mixed="true">
>          <xsd:extension base="ogc:ExpressionType"/>
>       </xsd:complexContent>
>    </xsd:complexType>
> 
> <xsd:complexType name="ExpressionType" abstract="true"/>
> 
> <xsd:element name="expression" type="ogc:ExpressionType" abstract="true"/>

This fragment uses substitution groups. If you compile your schemas
with the --generate-polymorphic option then the generated code will
contain support for this and will handle everything automatically.

Let's say you have a type which contains the expression element from
above:

<xsd:complexType name="Foo">
  <xsd:sequence>
    <xsd:element ref="ogc:expression"/>
  </xsd:sequence>
</xsd:complexType>

And you want to create an instance of Foo that contains the PropertyName
element instead of expression. To achieve this you simply set the 
expression element to an object of type PropertyNameType (even though
its static type is ExpressionType):

PropertyNameType& pnt = ...

Foo foo (pnt);

When you serialize this object the generated code will automatically
use the PropertyName element instead of expression.


> Another problem i have is the there are not classes genereated for some
> elements (and their types).
> 
> <xsd:element name="Not"  type="ogc:UnaryLogicOpType"
> substitutionGroup="ogc:logicOps"/>
> 
> <xsd:complexType name="UnaryLogicOpType">
>       <xsd:complexContent>
>          <xsd:extension base="ogc:LogicOpsType">
>             <xsd:sequence>
>                <xsd:choice>
>                   <xsd:element ref="ogc:comparisonOps"/>
>                   <xsd:element ref="ogc:spatialOps"/>
>                   <xsd:element ref="ogc:logicOps"/>
>                </xsd:choice>
>             </xsd:sequence>
>          </xsd:extension>
>       </xsd:complexContent>
>  </xsd:complexType>

As shown above, you don't need to worry about element names when
working with substitution groups. Simply use the required type
(UnaryLogicOpType in this case) when creating your object model 
and the generated code will take care of using the right element
name during serialization.

Boris




More information about the xsd-users mailing list