[xsd-users] XML namespace in generated class?

Boris Kolpackov boris at codesynthesis.com
Mon Dec 1 04:49:10 EST 2008


Hi Steve,

Steve Sloan <steve at finagle.org> writes:

> Is there any way to access the schema namespace (i.e. 'targetNamespace') 
> from the corresponding generated classes at runtime?
> 
> I notice that the generated DOM parsing functions check for the 
> appropriate namespace, but use several string constants instead of a 
> const static class member to store it.  Moving the namespace to a 
> class-level constant would also allow for a default namespace map when 
> serializing (and parsing).  Is there a particular reason why it isn't 
> this way now?

It is not done this way at the moment because we generate parsing and
serialization functions (as opposed to classes) for global elements.
As such there is no convenient place to provide access to this 
information.

Having said that, for the next release of XSD we have implemented
an alternative mode where we generate classes instead of functions
for root elements. Besides other useful things, these classes provide
access to element's name and namespace. 

If you would like to give it a try, there is a pre-release binary
(essentially XSD 3.2.0 plus this feature) available for i686 Linux:

http://codesynthesis.com/~boris/tmp/xsd-3.3.0.a1-i686-linux-gnu.tar.bz2

We can also build binaries for other platforms is needed. The NEWS file
entries for this feature are as follows:

  * New option, --generate-element-type, triggers generation of types
    instead of parsing/serialization functions for root elements. This
    is primarily useful to distinguish object models with the same root
    type but with different root elements. For more information refer
    to the messaging example and Section 2.9.1, "Element Types" in the
    C++/Tree Mapping User Manual.

  * New option, --generate-element-map, triggers generation of a root
    element map. The element map allows uniform parsing and serialization
    of multiple root elements. This option can only be used together with
    --generate-element-type. For more information refer to the messaging
    example and Section 2.9.2, "Element Map" in the C++/Tree Mapping
    User Manual.

I suggest that you check the messaging example in examples/cxx/tree/ and
Section 2.9 in the C++/Tree Mapping User Manual located in

documentation/cxx/tree/manual/cxx-tree-manual.pdf

Boris




More information about the xsd-users mailing list