[xsd-users] abstract and substitutionGroup

Ray Lischner rlischner at proteuseng.com
Thu May 6 11:18:15 EDT 2010


We are trying to use substitutionGroup and abstract types. Below is a simplified form of our schema:

<xsd:schema xmlns:xsd=http://www.w3.org/2001/XMLSchema xmlns:msg="msg" targetNamespace="msg" elementFormQualified="true">
  <xsd:complexType name="Base" abstract="true"/>
  <xsd:complexType name="Der1">
    <xsd:complexContent>
      <xsd:extension base="msg:Base">
        <xsd:sequence>
          <xsd:element name="i" type="xsd:int"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>
  <xsd:complexType name="Der2">
    <xsd:complexContent>
      <xsd:extension base="msg:Der1">
        <xsd:sequence>
          <xsd:element name="s" type="xsd:string"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>
  <xsd:complexType name="Msg">
    <xsd:sequence>
      <xsd:element ref="msg:base"/>
    </xsd:sequence>
  </xsd:complexType>
  <xsd:element name="message" type="msg:Msg"/>
  <xsd:element name="base1" type="msg:Base"/>
  <xsd:element name="der1" type="msg:Der1" substitutionGroup="msg:base"/>
</xsd:schema>

A program constructs a Msg object as follows:

#include "schema.h"
int main()
{
   xml_schema::namespace_infomap ns;
   ns[""].name = "msg";
   msg::Der2 d(1, "str");
   msg::Msg m(d);
   msg::message(std::cout, m, ns);
}

The resulting document is:

<message xmlns="msg">
  <base xsi:type="Der2">
    <i>1</i>
    <s>str</s>
  </base>
</message>

The author of the schema claims that the abstract property should prevent the use of <base>, and therefore force the use of <der1>:

<message xmlns="msg">
  <der1 xsi:type="Der2">
    <i>1</i>
    <s>str</s>
  </der1>
</message>

The author of the schema therefore claims that Code Synthesis has a defect. I'm afraid this dispute exceeds my level of XML Schema subtlety. Can you offer any help or suggestions? Thank you.

Ray Lischner,
Senior Member of Technical Staff
133 National Business Pkwy, Ste 150     t. 443.539.3448
Annapolis Junction, MD 20701                c. 410.854.5170
rlischner at proteuseng.com                     f. 443.539.3370

This electronic message and any files transmitted with it contain information
which may be privileged and/or proprietary. The information is intended for use
solely by the intended recipient(s). If you are not the intended recipient, be
aware that any disclosure, copying, distribution or use of this information is
prohibited. If you have received this electronic message in error, please advise
the sender by reply email or by telephone (443.539.3400) and delete the message.


More information about the xsd-users mailing list