[xsd-users] Polymorphism : Xml Validation Error

Chew kk chew.on.it at gmail.com
Fri Apr 17 07:56:52 EDT 2015


Hi,

I'm getting the following error when I tried out an example on
polymorphism. Appreciate if you could help out.

Error :
myFileName.xml:4:12 error: no declaration found for element 'address'
myFileName.xml:5:9 error: no declaration found for element 'city'
myFileName.xml:6:12 error: no declaration found for element 'country'
myFileName.xml:7:12 error: element 'address' is not allowed for content
model '(name)'

supermen.xsd file :
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:complexType name="person">
    <xsd:sequence>
      <xsd:element name="name" type="xsd:string"/>
    </xsd:sequence>
  </xsd:complexType>
  <xsd:complexType name="superman">
    <xsd:complexContent>
      <xsd:extension base="person">
        <xsd:sequence>
          <xsd:element name="address" type="xsd:string"/>
          <xsd:element name="city" type="xsd:string"/>
          <xsd:element name="country" type="xsd:string"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>
  <xsd:element name="supermen" type="person"/>
</xsd:schema>

myFileName.xml file :
<?xml version="1.0" encoding="utf-8"?>
<supermen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="
http://www.w3.org/2001/XMLSchema" xsi:type="superman"
xsi:noNamespaceSchemaLocation="supermen.xsd">
  <name>abc</name>
  <address>789</address>
  <city>123</city>
  <country>456</country>
</supermen>

Driver :
int
main (int argc, char* argv[])
{
  if (argc != 2)
  {
    cerr << "usage: " << argv[0] << " supermen.xml" << endl;
    return 1;
  }

  try
  {
    auto_ptr<person> sm (supermen(argv[1]));
  }
  catch (const xml_schema::exception& e)
  {
    cerr << e << endl;
    return 1;
  }
}

Thank You,
chew


More information about the xsd-users mailing list