[xsd-users] Basic questions

bruno.marotta at fortis.com bruno.marotta at fortis.com
Fri Nov 9 07:57:03 EST 2007


Hi Boris,

thanks for the reply. For what I've understood, I will have to a mix between the XSD utility functions and the pure Xerces one. 

I will try it and I'll let you know.

Thanks,

Bruno 

-----Original Message-----
From: Boris Kolpackov [mailto:boris at codesynthesis.com] 
Sent: Friday, November 09, 2007 1:44 PM
To: Marotta Bruno
Cc: xsd-users at codesynthesis.com
Subject: Re: [xsd-users] Basic questions

Hi Bruno,

bruno.marotta at fortis.com <bruno.marotta at fortis.com> writes:

> The thing is that main xsd doesn't define its type:
>
> 	<xs:element name="CDOEvaluator"/>

This declaration is equivalent to:

<xs:element name="CDOEvaluator" type="xs:anyType"/>

Which means CDOEvaluator element can contain pretty much anything
and no validation will be done on its content. This most likely is
not something that the author of the schema intended, but if it
is then read on.


> The xml I have to generate is something like this:
>
> <CDOEvaluator>
> 	<InputForSDR>
> ...
>
> I can create my CDOEvaluator and InputForSDR node like this:
>
> 	xml_schema::type cdoEvaluator
> 	...
> 	InputForSDR inputForSDR(p);
>
> But how can I add the inputForSDR to the cdoEvaluator?


You cannot since xml_schema::type (mapping for xsd:anyType) does not
know anything about InputForSDR or any other content.

If there is global element InputForSDR defined in one of your schemas,
then you can write the <CDOEvaluator> openning tag and </CDOEvaluator>
closing tag yourself and then serialize InputForSDR using the XSD-generated
object model (you will need to pass the no_xml_declaration flag to the
serializer function). For an example that does pretty much exactly this
see examples/cxx/tree/streaming/ in the XSD distribution.

If you do not have the InputForSDR element (and cannot change the
schema to define one) then things are bit more complicated. You will
need to (1) create a DOMDocument with the CDOEvaluator as root element,
(2) add the InputForSDR element under it, then (3) serialize the
InputForSDR instance (inputForSDR) into InputForSDR element, and,
finally, (4) serialize the DOM document to XML.

Steps 1, 2, and 4 are covered in the C++/Tree Mapping FAQ, Section 3:

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

Step 3 is actually quite easy:

DOMElement* inputForSDRElement = ...;

*inputForSDRElement << inputForSDR;


Let me know if you run into any problems.

Boris


= = = = = = = = = = = = = = = = = = = = = = = = =
Fortis disclaimer :
http://www.fortis.be/legal/disclaimer.htm

Privacy policy related to banking activities of Fortis:
http://www.fortis.be/legal/privacy_policy.htm
= = = = = = = = = = = = = = = = = = = = = = = = =






More information about the xsd-users mailing list