[xsde-users] Generate aggregate that handles multiple root elements

Boris Kolpackov boris at codesynthesis.com
Mon Jan 13 10:03:11 EST 2014


Hi Jonathan,

Jonathan Haws <Jonathan.Haws at sdl.usu.edu> writes:

> Is it possible to take a schema that defines multiple valid root elements
> and generate an aggregate that will parse/serialize based on what it sees?
>
> For example, if I have a schema that defines root elements A, B, and C can I
> generate a parser that will accept:
> 
> <A attr="1">
> 	<B></B>
> 	<C></C>
> </A>
> 
> As well as,
> 
> <B attr="1">
> 	<C></C>
> </B>
> 
> And,
> 
> <C attr="1"></C>
> 
> And determine what the root element is for me and parse the document?

The problem with supporting something like is that the returned types
are different. Instead, XSD/e allows you to determine the root element
and supply a corresponding parser. See the 'multiroot' example for how
to set this up.


> I would also like to be able to serialize and not worry about the 
> root element and just have some routines that look something like:
> 
> Serialize(A&);
> Serialize(B&);
> Serialize(C&);
> 
> Serializing would be the easy part if I had to do it myself.

The problem with supporting something like this is that, in the general
case, there could be two elements with the same type. So in this case
you will have to do it yourself.

Boris



More information about the xsde-users mailing list