[xsd-users] vocabulary-specific types for simple elements
Bill Pringlemeir
bpringle at sympatico.ca
Tue Jan 12 14:58:52 EST 2010
On 12 Jan 2010, sutambe at dre.vanderbilt.edu wrote:
> Hi,
>
> I was wondering if there is a way in xsd (tool) to generate classes
> that wrap simple content such as <xs:element name="price"
> type="xs:int" />
> As far as I know, the parent class of such an element gets a set of
> overloaded price() methods that essentially return C++ int. Instead, I
> was thinking of a class named "price".
>
> Based my limited knowledge of the implementation of the generator, I
> think if we force it to consider all elements as complex elements
> (using a command-line switch), we can get the desired effect. Am I
> wrong? Some extra name mangling might be necessary to resolve name
> collisions.
You can do this is various ways that I can think of.
1) You could insert a complex type that wraps a price.
2) You can use --type-regex and change the type of price.
Use a wrapper class in all users of price to return the class.
The first is the least effort, but impossible if you can not modify
the schema for some reason. You could just 'patch' the schema before
generation so that is true to the online variant.
The second option is more work. You need to modify both the interface
and all of the users to move from returning a simple type to a class.
You can also customize a 'simple type'. The customization guide has
information on how to do this for a date class. This is probably more
like what you were thinking of. I have implemented this with a
simpleType. A simple type is schema typedef. I think it is difficult
if your schema has hard coded types as 'int'. In this case, I am
pretty sure you have to wrap all generate user classes as well.
I sure Boris might have a better answer.
fwiw,
Bill Pringlemeir.
More information about the xsd-users
mailing list