[xsd-users] RE: keeping annotations/comments in xml file

Inna Grois inna at hyperroll.com
Thu Aug 23 04:27:56 EDT 2007


I am sorry, but I cannot find "custom/wildcard example".
Can you lease give me a link to it.

Thanks,
-Inna

-----Original Message-----
From: Boris Kolpackov [mailto:boris at codesynthesis.com] 
Sent: Thursday, August 23, 2007 10:11 AM
To: Inna Grois
Cc: xsd-users at codesynthesis.com
Subject: Re: [xsd-users] RE: keeping annotations/comments in xml file

Hi Inna,

In the future please keep your replies CC'ed to the xsd-users mailing
list. This way a) other developers who may have experienced a similar
problem can provide you with a solution b) questions and answers will
be archived and available to others with similar problems.

Inna Grois <inna at hyperroll.com> writes:

> I would like to get more details about the second possibility.
> You wrote:
>
> > Another, more elegant, way to do this would be to customize the
> > xml_schema::type type (a base type for all generated classes) with a
> > new DOMElement serialization operator that will copy the comments
from
>
> > the old DOM tree (that should be associated with the object model
> > using the keep_dom flag) to the new one.
>
> I have a couple of questions:
>
> If I use Keep_dom flag, then after parsing an xml node, the DOMElement
> of this node contains the DOM info of this node?

Yes, with the keep_dom flag, the corresponding DOM nodes and object
model
nodes are associated. You can obtain a DOM node from an object model
by calling the _node() function. See Section 3.2, "Flags and Properties"
in the C++/Tree Mapping User Manual:

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


> Is it means that the DOMElement in xml_schema::type type contains all
> the DOM info about current node including the comments of current
node?

It contains the original content so if there were comments, then yes,
they are preserved. Actually, I just checked and the default behavior
of the parsing functions appears to be to discard comments. This means
that you will need to do the XML-to-DOM parsing yourself. For more
information on how to do this see the multiroot example in 3.0.0
distribution and/or the C++/Tree mapping FAQ:

http://wiki.codesynthesis.com/Tree/FAQ


> If so, what exactly should I do to copy the comments from the
DOMElement
> to the output document?
>
> if you can give me some simple example I will appreciate it very much.

You will need to do the following:

1. Customize the xml_schema::type. For more information on how to do
this
   see the C++/Tree Mapping Customization Guide, particularly sections 1
   and 4:

   http://wiki.codesynthesis.com/Tree/Customization_guide

   In your customization, you should simply inherit from the original
   xml_schema::type, provide all the constructors that are found in
   the original xml_schema::type (see the custom/calendar example),
   and add your own operator<< (DOMElement, const xml_schema::type&)
   (see the custom/wildcard example).

2. In your implementation of operator<< (DOMElement, xml_schema::type),
   you will first call the original operator<< and then call _node()
   to obtain the original node and copy any comments to the new node.

3. You will need to parse your XML to DOM and preserve comments
   (parser->setFeature (XMLUni::fgDOMComments, true)). Then parse the
   DOM document to the object model with the keep_dom flag.


Hopefully in the next release of XSD we will add an example that shows
how to do all this.

hth,
-boris




More information about the xsd-users mailing list