[xsd-users] Does polymorphic serializer support streaming?

Boris Kolpackov boris at codesynthesis.com
Mon Jun 8 05:31:50 EDT 2015


Hi Danny,

Danny Yue <sheepduke at 163.com> writes:

> When building the whole tree and calling `tree_(std::cout, tree, map)',
> I've got:
>
> <tree xmlns="http://example.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>   <node color="red" name="name" smell="good" xsi:type="apple"/>
>   <node color="yellow?" name="orange" xsi:type="orange"/>
> </tree>'
> which is exactly what I want.
> 
> However, when I use serializer like:
>
> s.start(std::cout);
> s.next_open("tree", tree);
> s.next("apple", *apple);
> s.next("orange", *orange);

Well, you are explicitly specifying the element names as the first
argument. So you get them in the output. If you want "node" and
xsi:type, then you will need to specify them as "node" and also
add the xsi:type yourself. If you want to do it in a generic
way, then you can take a look at how the generated code/runtime
figure out what to put in xsi:type and implement the same logic
(all the underlying type maps are publicly accessible).

Boris



More information about the xsd-users mailing list