[xsde-users] Serializer/Parser with anyType
Boris Kolpackov
boris at codesynthesis.com
Wed Jul 16 07:37:42 EDT 2008
Hi Khuong,
Khuong Nguyen Thi Lien <ntlkhuong at tma.com.vn> writes:
> 1. How to serialize the element "ok" as the below schema fragment:
>
> <xs:complexType name="rpcReplyType">
> <xs:choice>
> <xs:element name="ok"/>
> <xs:group ref="rpcResponse"/>
> </xs:choice>
> <xs:attribute name="message-id" type="messageIdType" use="optional"/>
> <xs:anyAttribute processContents="lax"/>
> </xs:complexType>
Element 'ok' is (implicitly) of type xsd:anyType which is a special
type that can contain any attributes/elements/text in any order.
To serialize an element of this type you will need to implement
the xml_schema::any_type_sskel serializer skeleton, for example:
struct ok_any_type_simpl: xml_schema::any_type_sskel
{
virtual void
_serialize_attributes ()
{
...
}
virtual void
_serialize_content ()
{
...
}
};
Inside the _serialize_attributes() and _serialize_content()
functions you would normally call the low-level XML serialization
function as described in Section 5.4, "Element Wildcard Callbacks"
in the Embedded C++/Serializer Mapping Getting Started Guide:
http://www.codesynthesis.com/projects/xsde/documentation/cxx/serializer/guide/#5.4
In case all you need is an empty 'ok' element, then you can simply use
the default xml_schema::any_type_simpl provided by the XSD/e runtime.
> 2. How to parse the element "select" as the below schema fragment:
>
> <xs:complexType name="filterInlineType">
> <xs:complexContent>
> <xs:extension base="xs:anyType">
> <xs:attribute name="type" type="FilterType" default="subtree"/>
> <xs:attribute name="select"/>
> </xs:extension>
> <!-- if type="xpath", the xpath expression
> appears in the select element -->
> </xs:complexContent>
> </xs:complexType>
Similarly to the previous case, attribute 'select' is (implicitly) of
type xsd:anySimpleType which is a special type that can contain any
text. To parse an element of this type you will need to implement
the xml_schema::any_simple_type_pskel parser skeleton, for example:
struct select_any_simple_type_pimpl: xml_schema::any_simple_type_pskel
{
virtual void
_any_characters (const xml_schema::ro_string& s)
{
// s contains raw character data
}
};
Boris
More information about the xsde-users
mailing list