[xsd-users] Parsing and validation from CDR stream
boris at codesynthesis.com
Fri Jul 23 09:46:16 EDT 2010
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:
root (buf, *copy, map); // map specified schema
copy = root (buf, "tmp.xml"); // tmp.xml name for diagnostics
More information about the xsd-users