[xsd-users] Trouble serializing subclasses.
Charles Beyer
cjbeyer at gmail.com
Sat May 17 00:21:01 EDT 2008
I'm having trouble getting the codesynthesis xsd-tree serializer to
fully serialize a list of objects. Perhaps someone here can point out
my misstep.
My schema has a list of baseclass elements:
list of elements of A:
CT AList
E Values A
complex type A:
CT A
E ulong ID
complex type B extends A:
CT B : A
E ulong JD
The generated classes are as you'd imagine.
class A: public ::xml_schema::type
{
...
typedef ::xml_schema::unsigned_long ID_type;
...
::xsd::cxx::tree::one< ID_type > ID_;
}
class B: public A
{
...
typedef ::xml_schema::unsigned_long JD_type;
...
::xsd::cxx::tree::one< ID_type > JD_;
}
class AList: public ::xml_schema::type
{
typedef A Values_type;
typedef ::xsd::cxx::tree::sequence< Values_type > Values_sequence;
...
Values_sequence Values_;
}
I'm tying to serialize an AList that contains classes B:
// convert the list into an XML string
std::string msg;
std::ostringstream oss;
xml_schema::namespace_infomap map;
map[""].name = "stuff";
map[""].schema = "Schema.xsd";
AList_ (oss, aList, map);
msg = oss.str();
It only serializes the Values as type A, not the subclass B:
<AList xmlns="stuff"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="stuff Schema.xsd">
<Values>
<ID>99999999999</ID>
</Values>
<Values>
<ID>2</ID>
</Values>
</AList>
Using the exact same schema in .NET and C#, it properly serializes AList:
<AList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="stuff">
<Values xsi:type="B">
<ID>99999999999</ID>
<JD>5</JD>
</Values>
<Values xsi:type="B">
<ID>2</ID>
<JD>10</JD>
</Values>
</AList>
So, that's it. I'm trying to get the xsd-tree serializer to work like
my cs xsd serializer. Any pointers?
--
Charles Beyer,
cjbeyer at gmail.com
Austin, TX
More information about the xsd-users
mailing list