[xsd-users] Parsing and validation from CDR stream

Romain rc.mail.dev at gmail.com
Fri Aug 6 00:19:36 EDT 2010


Hi,

Sorry for the late reply.

The scenario you have described is correct.

One part of my application serializes C++ data to CDR. For what I
understand, there is no validation at this stage.

The other part of my application receives the CDR data, deserializes the CDR
to C++ data (also no validation at that stage correct?).

That's why I need the validation, because there might be some invalid data
(boundaries errors, etc.).

Any other suggestions on how I could handle this case?

Thank you.

Regards,

Romain


On Fri, Jul 23, 2010 at 9:46 PM, Boris Kolpackov <boris at codesynthesis.com>wrote:

> Hi Romain,
>
> Romain <rc.mail.dev at gmail.com> writes:
>
> > std::auto_ptr<type> r = root ("root.xml");
> >
> > // Save to a CDR stream.
> > //
> > ACE_OutputCDR ace_ocdr;
> > xml_schema::ostream<ACE_OutputCDR> ocdr (ace_ocdr);
> >
> > ocdr << *r;
> >
> > // Load from a CDR stream.
> > //
> > ACE_InputCDR ace_icdr (buf, size);
> > xml_schema::istream<ACE_InputCDR> icdr (ace_icdr);
> >
> > std::auto_ptr<object> copy (new object (icdr));
> >
> > Is it possible to parse and validate the XML message after loading
> > from the CDR stream?
>
> I am not sure what you mean by parse and validate in this context.
> The object model extracted from CDR ('copy' in this case), is
> already parsed (in XML sense). That is, it is equivalent to 'r'
> in the above example. You also don't normally need to validate
> this object model since, unlike XML, the CDR representation is
> constructed by the generated code and is valid provided you have
> serialized a valid object model in the first place.
>
> The only scenario that I can think of that may make you want to
> validate the object model after extraction from CDR is if you are
> not sure the original object model that was saved to CDR was valid
> (for example, it was created by the application or you disabled
> validation during XML parsing). In this case the only way to validate
> the data is to serialize it in XML into an in-memory buffer and
> then re-parse it with validation. Something along these lines:
>
> std::stringstream buf;
> root (buf, *copy, map);       // map specified schema
> copy = root (buf, "tmp.xml"); // tmp.xml name for diagnostics
>
> Boris
>


More information about the xsd-users mailing list