[xsd-users] naming issue w/serialization and parsing

Rizzuto, Raymond Raymond.Rizzuto at sig.com
Tue Jul 1 17:59:56 EDT 2008


I ended up with this command line, which gives me what I was looking
for:

xsd.exe cxx-tree  --output-dir . --hxx-suffix .hxx --cxx-suffix .cxx
--ixx-suffix .ixx --fwd-suffix
-fwd.hxx --generate-serialization --generate-polymorphic
--generate-ostream --generate-doxygen
--generate-comparison --generate-from-base-ctor --generate-wildcard
--generate-intellisense
--root-element-all --anonymous-regex "|.* .* (.+/)*(.+)|$2|"
--serializer-regex "/(.+)/serialize_$1/"
--parser-regex "/(.+)/parse_$1/" --modifier-regex "/(.+)/set_$1/"
--accessor-regex "/(.+)/get_$1/"

Ray

-----Original Message-----
From: Rizzuto, Raymond
Sent: Tuesday, July 01, 2008 4:16 PM
To: 'Boris Kolpackov'
Subject: RE: [xsd-users] naming issue w/serialization and parsing

Boris,

Thanks for the detailed answers.  I think part of the problem I have is
in understanding the mapping from the schema to the object model that
XSD generates.  I'm new to schema, and the fact that XSD insulates me
from the schema is a double edged sword.

I think I can use the various regex's you provide to generate the names
the way I want them.  I basically would like to use knr style (i.e.
underscore separators, but no case conversion), however I want the
accessor functions to prepend get_, and the modifiers to prepend set_,
serializer prepend serialize_, etc.

I'm sure I can figure this out over time, however I have a couple of
suggestions that might make this kind of customization easier:

- possibly allow finer granularity to specify the style.  I.e.
--accessor-type java
- document the entire set of base regex's for knr, java, etc. to make it
easier to create a mix and match version
- allow a style to be defined in a file and referenced.  i.e.
--load-style myStyle.def.  This would also help with corporate coding
conventions.

Anyway, I am forging ahead with some success.  Thanks again!

Ray

-----Original Message-----
From: Boris Kolpackov [mailto:boris at codesynthesis.com]
Sent: Tuesday, July 01, 2008 9:52 AM
To: Rizzuto, Raymond
Cc: xsd-users at codesynthesis.com
Subject: Re: [xsd-users] naming issue w/serialization and parsing

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

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.




More information about the xsd-users mailing list