[xsd-users] Specifying Element content for "anyType" Elements
Jan Klimke
jan.klimke at hpi.uni-potsdam.de
Thu Sep 11 17:02:06 EDT 2008
Hi Boris,
thank you for your answer on this issue. It helped a lot until now. But
there appeared two further issues with that.
First of all the complete schema which is part of my problem:
http://schemas.opengis.net/filter/1.1.0/filter.xsd
A i have said, i still got some problems:
1.
i tried to create an PropertyIsEqualTo element which is defined as follows:
<xsd:element name="PropertyIsEqualTo"
type="ogc:BinaryComparisonOpType"
substitutionGroup="ogc:comparisonOps"/>
<xsd:complexType name="BinaryComparisonOpType">
<xsd:complexContent>
<xsd:extension base="ogc:ComparisonOpsType">
<xsd:sequence>
<xsd:element ref="ogc:expression" minOccurs="2"
maxOccurs="2"/>
</xsd:sequence>
<xsd:attribute name="matchCase" type="xsd:boolean"
use="optional" default="true"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
I created the object with the following code (in a seperate method):
ogc::FilterType filter = ogc::FilterType();
ogc::PropertyNameType& propertyName =(ogc::PropertyNameType&)xml_schema::string("app::isActive"); //Is this correct or how do i have to assign an element value ? Is this kind of upcasting wanted ?
ogc::LiteralType& value = (ogc::LiteralType&)xml_schema::string("true");
ogc::BinaryComparisonOpType isEqual = ogc::BinaryComparisonOpType();
ogc::BinaryComparisonOpType::expression_sequence& expressions =
ogc::BinaryComparisonOpType::expression_sequence();
expressions.push_back(propertyName); //here i put the instance of propertyName into an expression collection
expressions.push_back(value);
isEqual.expression(expressions);
return filter;
When serializing the following XML is generated for the element
(appended to a wfs:Query element):
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<p1:Query xmlns:p1="http://www.opengis.net/wfs"
typeName="app:CollaborationSession" xmlns:p2="http://www.opengis.net/ogc">
<p2:Filter>
<p2:PropertyIsGreaterThanOrEqualTo matchCase="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<p2:expression xmlns:p3="http://www.w3.org/2001/XMLSchema" xsi:type="p3:string">app::isActive</p2:expression>
<p2:expression xmlns:p3="http://www.w3.org/2001/XMLSchema"xsi:type="p3:string">true</p2:expression>
</p2:PropertyIsGreaterThanOrEqualTo>
</p2:Filter>
</p1:Query>
As you can see, the generated element is not the desired one but
"PropertyIsGreaterThanOrEqualTo".
This element is defined like the PropertyIsEqualTo element:
<xsd:element name="PropertyIsGreaterThanOrEqualTo"
type="ogc:BinaryComparisonOpType" substitutionGroup="ogc:comparisonOps"/>
Because they are both of the same type no other class as
ogc:BinaryComparisonOpType is generated. And also the instance of
PropertyNameType and LiteralType where not serialized as the elements i
wanted. Where is my fault ?
2.
The other issue i found was assigning boolean values as a LiteralType
instance. The does not work because xml_schema::boolean does not
derrive from xml_schema::type. Is there something like a wrapper for that ?
Greetings,
Jan
Boris Kolpackov schrieb:
> 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