[xsd-users] Fixed Attributes

George Vassilakes george at sbdev.net
Thu Oct 16 11:36:33 EDT 2008


Hi,

Is it possible to get the XSD generated classes when serializing to XML 
to also include the fixed value attributes?
for example if I have the following types

Base type of all messages on Message.xsd
=============================
  <!-- define the main message base -->
  <xsd:complexType name="MfeEpeMessageBase" abstract="true">
    <xsd:attribute name="serviceName" type="xsd:string"/>
  </xsd:complexType>
  <xsd:element name="MfeEpeMessageBase" type="MfeEpeMessageBase"/>

On another file DTMessage.xsd that includes Message.xsd I define first a 
restriction that sets the service name and then lots of messages that 
inherit from it
==============================
  <!-- define the message base class for the DT service -->
  <xsd:complexType name="DT_ServiceMessageBase" abstract="true">
    <xsd:complexContent>
      <xsd:restriction base="MfeEpeMessageBase">
        <xsd:attribute name="serviceName" type="xsd:string" 
fixed="DTService"/>
      </xsd:restriction>
    </xsd:complexContent>
  </xsd:complexType>
  <xsd:element name="DT_ServiceMessageBase" type="DT_ServiceMessageBase" 
substitutionGroup="MfeEpeMessageBase"/>

  <!-- Encrypt disk command take as a parameter the disk details-->
  <xsd:complexType name="DT_EncryptDiskCmd">
    <xsd:complexContent>
      <xsd:extension base="DT_ServiceMessageBase">
        <xsd:sequence>
          <xsd:element name="hdd" type="DT_HddType"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>
  <xsd:element name="DT_EncryptDiskCmd" type="DT_EncryptDiskCmd" 
substitutionGroup="DT_ServiceMessageBase"/>

If I create instances of the DT_EncryptDiskCmd class and serialise them 
and load the using the DTMessage.xsd then the serviceName is 
automatically set by the fixed value.
However if I parse the XML using the Message.xsd the value is not set as 
this was not output by the serialization.
Is it possible to get it to set these these fixed attributes on the XML 
when serializing from C++ to XML?

Regards
George




More information about the xsd-users mailing list