[xsd-users] naming issue w/serialization and parsing
Boris Kolpackov
boris at codesynthesis.com
Tue Jul 1 09:51:58 EDT 2008
Hi Ray,
Rizzuto, Raymond <Raymond.Rizzuto at sig.com> writes:
> For classes that are lowercase (header, message, etc) the output
> serialization function names are getting an underscore appended:
>
> message_ (::std::ostream& os,
>
> [...]
>
> Classes that are upper case (Instrument, etc) have a serialize
> function that is a lower case version of the class name:
>
> instrument (::std::ostream& os,
Serialization (and parsing) functions are generated for global elements,
not for types. This is to match the XML Schema concept that only global
elements are valid document roots.
The underscore is appended to the parsing/serialization functions if
there is a type with the same name (note that if a global element
defines an anonymous type, this type will have the same name as the
element and parsing/serialization functions will have '_'; you can
change this with the --anonymous-regex option).
> Since this is a bit confusing, I'd rather have the serialize name be
> something like Class_serialize.
As explained above, you can only make it <element>_serialize.
> I was able to almost get the behavior I wanted with
> --serializer-regex /(.+)/$1_serialize/ - the problem is that
> Instrument's serialization becomes instrument_serialize.
I guess you have a type named Instrument and a global element named
instrument. If this naming style is used consistently in your schema
then you can get the desired behavior by uppercasing the first latter:
--serializer-regex /(.+)/\u$1_serialize/
> On a related issue, I have elements in the schema that differ only
> in the case of the first letter (OrderInstruction and orderInstruction).
> orderInstruction is actually derived from OrderInstruction. The problem
> is I only see serialization functions for orderInstruction:
This is probably because you have a global element for orderInstruction
and not for OrderInstruction.
Also note that you can serialize any type using serialization operators.
This requires a bit of extra work but it can be done, for example:
OrderInstruction& oi = ...
DOMDocument* doc = ... // create a DOM document, see FAQ 3.1
DOMElement* root = doc->getDocumentElement ();
*root << oi;
// Serialize doc to XML, see FAQ 3.2
Boris
More information about the xsd-users
mailing list