[xsd-users] generic framework vs. XML functions
boris at codesynthesis.com
Wed Mar 21 10:26:51 EDT 2007
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.,
<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...
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 652 bytes
Desc: Digital signature
Url : http://codesynthesis.com/pipermail/xsd-users/attachments/20070321/cccfc59f/attachment.pgp
More information about the xsd-users