[xsd-users] vocabulary-specific types for simple elements

Sumant Tambe sutambe at dre.vanderbilt.edu
Wed Jan 13 10:07:32 EST 2010


Hi Boris,

>> 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".
> 
> No, there is no way to do this. It is also not clear what extra 
> functionality such a class would have to justify the overhead.

I see a couple of advantages of doing it.

1. The data structure representing information remains abstract behind 
the interface of the generated class. That allows easy changes in the 
schema without breaking (some part of) the client code. Say for 
instance, regular strings to an enumeration of strings.

2. The elements that logically belong to different parts of XML, can be 
distinguished at the type level. For instance, if book titles and author 
names, both are represented using strings, it is not clear when you see 
a string object whether its a title or name. Some extra type-safety can 
be achieved if they have their respective classes.

Also, other than extra classes, do you see any other overhead of such an 
approach.

Thanks,

Sumant.



More information about the xsd-users mailing list