[xsd-users] polymorphism problem when serialization to xml

liyubo liyubo at dayang.com.cn
Wed Nov 20 06:53:21 EST 2013


Hi, I have a problem when try to construct a xml using XSD.

I try to modify the sample project  "CodeSynthesis XSD 3.3\examples\cxx\tree\polymorphism" to do this.

here is my code 

int
main (int argc, char* argv[])
{
      ::supermen all;

      ::supermen::person_sequence seqPerson;

      person p("Normal");
      superman s("Super",true);
 
      seqPerson.push_back(p);
      seqPerson.push_back(s);

      all.person(seqPerson);

      xml_schema::namespace_infomap map;
      map[""].schema = "supermen.xsd";

      supermen_(std::cout, all, map);
}


The output in console is

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<supermen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="supermen.xsd">

  <person>
    <name>Normal</name>
  </person>

  <person>
    <name>Super</name>
  </person>

</supermen>

Why the second element is still "person" but not "superman" ? How to fix this to make the "person_sequence" polymorphism?

2013-11-20



liyubo


More information about the xsd-users mailing list