[xsd-users] generic framework vs. XML functions

Ray Lischner rlischner at proteus-technologies.com
Wed Mar 21 15:59:07 EDT 2007


One solution is to generate a class for each root element instead of or in addition to the global functions. The class would have members to provide the root element name and namespace. The functor class could have overloaded operators for all the currently global functions. Automatically define an instance of the class with the element name, and you would have a solution that is nearly source-level compatible with existing code, and provides the necessary information for anyone who needs the element name and namespace programmatically.
 
Just a suggestion.
--
Ray Lischner, Proteus Technologies

________________________________

From: Boris Kolpackov [mailto:boris at codesynthesis.com]
Sent: Wed 3/21/2007 10:26 AM
To: Ray Lischner
Cc: xsd-users at codesynthesis.com
Subject: Re: [xsd-users] generic framework vs. XML functions



Hi Ray,

Ray Lischner <rlischner at proteus-technologies.com> writes:

> We are writing a framework that processes objects of many different
> Code Synthesis-generated types. We'd like to be able to write a
> single function that can serialize any such object to XML. One of
> the hurdles is that the name and namespace of the root element are
> encoded as strings hardcoded into functions. I see no way to write
> normal C++ code to extract that information. The framework, therefore,
> requires the caller to supply the root element name and namespace as
> arguments, which is error-prone and redundant.
>
> Is there any other way to deal with this problem?

This problem is conceptually difficult to solve because your objects
are of some XML Schema types and XML Schema types can be used for
several elements, e.g.,

<complexType name="Foo">
  ...
</complexType>

<element name="foo" type="Foo"/>
<element name="bar" type="Foo"/>

As a result it would be wrong to associate an element name with a
type. In your case case it is probably one-to-one relationship but
in general it is not so.

I don't see any clean way to solve this in an automatic way.
Another alternative to the manual method you suggested (passing
element name to the function) would be to have some kind of a
global map which is manually populated and maps typeids to element
names. This is a pain to maintain though.

Or you could write a custom code generator that would generate
this map automatically...


hth,
-boris





More information about the xsd-users mailing list