The xsd:simpleContent type is used to either extend or restrict an existing simple type definition. In the case of extension, the common use is to add attributes to a simple type. ASN1C will generate a C structure in this case with an element called base that is of the simple type being extended. An example of this is as follows:
<xsd:complexType name="SizeType"> <xsd:simpleContent> <xsd:extension base="xsd:integer"> <xsd:attribute name="system" type ="xsd:token"/> </xsd:extension> </xsd:simpleContent> </xsd:complexType>
this results in the following generated C type definition:
typedef struct EXTERN SizeType { struct { unsigned system_Present : 1; } m; const OSUTF8CHAR* system_; OSINT32 base; } SizeType;
In this case, the attribute system
was added first (note the name change
to system_
which was the result of system
being determined to
be a C reserved word). The base
element is then added and is of type
OSINT32
, the default type used for xsd:integer
.
In the case of a simple content restriction, the processing is similar. A complete new separate type is generated even if the result of the restriction leaves the original type unaltered (i.e. the restriction is handled by code within the generated encode and/or decode function). This proves to be a cleaner solution in most cases than trying to reuse the type being restricted. For example:
<xsd:complexType name="SmallSizeType"> <xsd:simpleContent> <xsd:restriction base="SizeType"> <xsd:minInclusive value="2"/> <xsd:maxInclusive value="6"/> <xsd:attribute name="system" type ="xsd:token" use="required"/> </xsd:restriction> </xsd:simpleContent> </xsd:complexType>
This applies a restriction to the SizeType that was previously derived. In this case, the generated C type is as follows:
typedef struct EXTERN SmallSizeType { const OSUTF8CHAR* system_; OSINT32 base; } SmallSizeType;
In this case, the type definition is almost identical to the original
SizeType
. The only exception is that the bit mask field for optional
elements is removed—a consequence of the use=“required”
attribute that was
added to the system
attribute declaration. The handling of the
minInclusive
and maxInclusive
attributes is handled inside
the generated encode and decode function in the form of constraint checks.