[xsd-users] a problem with CDATA part

Boris Kolpackov boris at codesynthesis.com
Sun Mar 30 16:16:48 EDT 2008


Hi,

kun lv <lvkun2006 at gmail.com> writes:

> The output should like the string under:
>
> <param>
>     <! [CDATA[
>       <A></A>
>     ]]>
> <param>
>
> but the result i got is
>
> <param>
> &lt;! [CDATA[
> &lt;A&gt;&lt;/&gt;
> ]]&gt;
> <param>

There are two ways you can go about this:

1. You can serialize the object model to DOM, find the element in
   question, and convert the DOMText node that contains "<A></A>"
   to the DOMCDATASection node. Then you can serialize DOM to XML.
   For more information on how to do this, see the C++/Tree Mapping
   User Manual (the "Serialization" chapter), C++/Tree Mapping FAQ,
   and Xerces-C++ DOM documentation.

2. If this is a specific element that should be serialized as CDATA,
   then you can defined a new type for this element in XML Schema
   (make it inherit from xsd:string). Then you can customize the
   generated C++ class and override its serialization operator. In
   the serialization operator you will create a DOMCDATASection with
   element's content. For more information on how to do this, see
   the C++/Tree Customization Guide, custom/wildcard example (shows
   how to customize the serialization operator) and Xerces-C++ DOM
   documentation.

Boris




More information about the xsd-users mailing list