[xsd-users] Code Synthesis use question

Boris Kolpackov boris at codesynthesis.com
Tue Jul 15 17:01:11 EDT 2008


Hi Bryan,

Bryan Wilcox <azbwilcox at yahoo.com> writes:

> I have a data item in my schema that is represented by xsd:anySimpleType.
> In the generated code this is represented by an object of type 
> "typedef ::xsd::cxx::tree::simple_type< type > simple_type;"  I am
> trying to find an object in a list that has a value in this field
> based on a string I want to compare it to.  However, I am having
> problems doing comparisons on the objects based on simple_type.

xsd:anySimpleType is a special XML Schema type which allows any (simple)
content and the XSD-generated object model does not automatically extract
the data for elements/attributes of this type.

There aren't many reasons to prefer this type over, say, xsd:string since
you get exactly the same content. So the simplest way to resolve this
would be to replace xsd:anySimpleType with xsd:string in your schema.

If you cannot modify the schema, then there are several way to get to
the raw content of elements/attributes of this type. 

The first is to request the parsing function to establish association
between DOM nodes and object model nodes. This way you can obtain a
DOMNode corresponding to element/attribute of xsd:anySimpleType and
then get the text content from there. For more information see Section
5.1, "DOM Association" in the C++/Tree Mapping User Manual:

http://www.codesynthesis.com/projects/xsd/documentation/cxx/tree/manual/#5.1

As well as the 'mixed' example in examples/cxx/tree/mixed/.

The second approach involves customizing the type which contains
element/attribute of xsd:anySimpleType and extracting the data in
this type's parsing constructor. For more information on how to do this
see the 'wildcard' example in examples/cxx/tree/custom/wildcard. While
this example shows how to extract the data corresponding to XML Schema
wildcards, handling of elements/attributes with the xsd:anySimpleType
type will be pretty much the same.

Boris




More information about the xsd-users mailing list