You are here: Part 2: Core Concepts > Data Types and DDS Data Samples > Creating User Data Types with XML Schemas (XSD)

Creating User Data Types with XML Schemas (XSD)

You can describe data types with XML schemas (XSD). The format is based on the standard IDL-to-WSDL mapping described in the OMG document "CORBA to WSDL/SOAP Interworking Specification."

Example Header for XSD:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
 xmlns:dds="http://www.omg.org/dds" 
 xmlns:tns="http://www.omg.org/IDL-Mapped/" 
 targetNamespace="http://www.omg.org/IDL-Mapped/">
<xsd:import namespace="http://www.omg.org/dds" 
 schemaLocation="rti_dds_topic_types_common.xsd"/>
...
</xsd:schema>

Mapping Type System Constructs to XSD describes how to map IDL types to XSD. The Connext DDS code generator, rtiddsgen, will only accept XSD files that follow this mapping.

Mapping Type System Constructs to XSD

Type/Construct

Example

IDL

XSD

IDL

XSD

char

dds:char1 All files that use the primitive types char, wchar, long double and wstring must reference rti_dds_topic_types_common.xsd. See Primitive Types.

struct PrimitiveStruct { char char_member; };

<xsd:complexType name="PrimitiveStruct">
<xsd:sequence>
<xsd:element name="char_member"
minOccurs="1" maxOccurs="1"
type="dds:char">
</xsd:sequence>
</xsd:complexType>

wchar

dds:wchar2 All files that use the primitive types char, wchar, long double and wstring must reference rti_dds_topic_types_common.xsd. See Primitive Types.

struct PrimitiveStruct {
wchar wchar_member;
};

<xsd:complexType name="PrimitiveStruct">
<xsd:sequence>
<xsd:element name="wchar_member"
minOccurs="1" maxOccurs="1"
type="dds:wchar">
</xsd:sequence>
</xsd:complexType>

octet

xsd:
unsignedByte

struct PrimitiveStruct {
octet octet_member;
};

<xsd:complexType name="PrimitiveStruct">
<xsd:sequence>
<xsd:element name="octet_member"
minOccurs="1" maxOccurs="1"
type="xsd:unsignedByte">
</xsd:sequence>
</xsd:complexType>

short

xsd:short

struct PrimitiveStruct {
short short_member;
};

<xsd:complexType name="PrimitiveStruct">
<xsd:sequence>
<xsd:element name="short_member"
minOccurs="1" maxOccurs="1"
type="xsd:short"/>
</xsd:sequence>
</xsd:complexType>

unsigned short

xsd:
unsignedShort

struct PrimitiveStruct { unsigned short unsigned_short_member; };

<xsd:complexType name="PrimitiveStruct">
<xsd:sequence>
<xsd:element name= "unsigned_short_member" minOccurs="1" maxOccurs="1"
type="xsd:unsignedShort"/> </xsd:sequence>
</xsd:complexType>

long

xsd:int

struct PrimitiveStruct {
long long_member;
};

<xsd:complexType name="PrimitiveStruct">
<xsd:sequence>
<xsd:element name="long_member"
minOccurs="1" maxOccurs="1"
type="xsd:int"/>
</xsd:sequence>
</xsd:complexType>

unsigned long

xsd:
unsignedInt

struct PrimitiveStruct {
unsigned long unsigned_long_member;
};

<xsd:complexType name="PrimitiveStruct">
<xsd:sequence>
<xsd:element name= "unsigned_long_member"
minOccurs="1" maxOccurs="1"
type="xsd:unsignedInt"/> </xsd:sequence> </xsd:complexType>

long long

xsd:long

struct PrimitiveStruct {
long long long_long_member;
};

<xsd:complexType name="PrimitiveStruct"> <xsd:sequence>
<xsd:elementname= "long_long_member"
minOccurs="1" maxOccurs="1"
type="xsd:long"/>
</xsd:sequence>
</xsd:complexType>

unsigned long long

xsd:
unsignedLong

struct PrimitiveStruct {
unsigned long long unsigned_long_long_member;
};

<xsd:complexType name="PrimitiveStruct">
<xsd:sequence>
<xsd:element name= "unsigned_long_long_member"
minOccurs="1" maxOccurs="1"
type="xsd:unsignedLong"/>
</xsd:sequence>
</xsd:complexType>

float

xsd:float

struct PrimitiveStruct {
float float_member;
};

<xsd:complexType name="PrimitiveStruct">
<xsd:sequence>
<xsd:element name="float_member"
minOccurs="1" maxOccurs="1"
type="xsd:float"/> </xsd:sequence>
</xsd:complexType>

double

xsd:double

struct PrimitiveStruct {
double double_member;
};

<xsd:complexType name="PrimitiveStruct">
<xsd:sequence>
<xsd:element name="double_member"
minOccurs="1" maxOccurs="1"
type="xsd:double"/> </xsd:sequence> </xsd:complexType>

long
double

dds:
longDouble

struct PrimitiveStruct {
long double long_double_member;
};

<xsd:complexType name="PrimitiveStruct">
<xsd:sequence>
<xsd:element name= "long_double_member"
minOccurs="1" maxOccurs="1"
type="dds:longDouble"/>
</xsd:sequence>
</xsd:complexType>

boolean

xsd:boolean

struct PrimitiveStruct {
boolean boolean_member;
};

<xsd:complexType name="PrimitiveStruct">
<xsd:sequence>
<xsd:element name="boolean_member"
minOccurs="1" maxOccurs="1"
type="xsd:boolean"/> </xsd:sequence> </xsd:complexType>

unbounded string

xsd:string

struct PrimitiveStruct {
string string_member;
};

<xsd:complexType name="PrimitiveStruct">
<xsd:sequence>
<xsd:element name="string_member"
minOccurs="1" maxOccurs="1"
type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>

bounded string

xsd:string with restriction
to specify the maximum length

struct PrimitiveStruct {
string<20> string_member;
};

<xsd:complexType name= "PrimitiveStruct_string_member_BoundedString"> <xsd:sequence> <xsd:element name="item" minOccurs="1" maxOccurs="1"> <xsd:simpleType> <xsd:restriction base="xsd:string"> <xsd:maxLength value="20" fixed="true"/> </xsd:restriction> </xsd:simpleType> </xsd:element> </xsd:sequence> </xsd:complexType> <xsd:complexType name= "PrimitiveStruct"> <xsd:sequence> <xsd:element name="string_member" minOccurs="1" maxOccurs="1" type= "tns:PrimitiveStruct_string_member_BoundedString"/ </xsd:sequence> </xsd:complexType>

unbounded wstring

dds:wstring3All files that use the primitive types char, wchar, long double and wstring must reference rti_dds_topic_types_common.xsd. See Primitive Types.

struct PrimitiveStruct {
wstring wstring_member;
};

<xsd:complexType name="PrimitiveStruct">
<xsd:sequence>
<xsd:element name="wstring_member"
minOccurs="1" maxOccurs="1"
type="dds:wstring"/> </xsd:sequence> </xsd:complexType>

bounded wstring

xsd:wstring with restriction
to specify the maximum
length

struct PrimitiveStruct {
wstring<20> wstring_member;
};

<xsd:complexType name= "PrimitiveStruct_wstring_member_BoundedString"> <xsd:sequence> <xsd:element name="item" minOccurs="1" maxOccurs="1"> <xsd:simpleType> <xsd:restriction base="dds:wstring"> <xsd:maxLength value="20" fixed="true"/> </xsd:restriction> </xsd:simpleType> </xsd:element> </xsd:sequence> </xsd:complexType> <xsd:complexType name= "PrimitiveStruct"> <xsd:sequence> <xsd:element name="wstring_member" minOccurs="1" maxOccurs="1" type= "tns:PrimitiveStruct_wstring_member_BoundedString"/> </xsd:sequence> </xsd:complexType>

pointer

<!--
@pointer <true|false|1|0>
-->
Default (if not specified): false

struct PrimitiveStruct {
long * long_member;
};

<xsd:complexType name="PrimitiveStruct">
<xsd:sequence>
<xsd:element name="long_member"
minOccurs="1" maxOccurs="1"
type="xsd:int"/>
<!-- @pointer true -->
</xsd:sequence>
</xsd:complexType>

key
directive4 Directives are RTI extensions to the standard IDL grammar. For additional information about directives, see Using Custom Directives.

<!--
@key <true|false|1|0>
-->
Default (if not specified): false

struct KeyedPrimitiveStruct {
long long_member; //@key };

<xsd:complexType name="KeyedPrimitiveStruct">
<xsd:sequence>
<xsd:element name="long_member"
minOccurs="1" maxOccurs="1"
type="xsd:int"/> <!-- @key true --> </xsd:sequence>
</xsd:complexType>

resolvename directive5 Directives are RTI extensions to the standard IDL grammar. For additional information about directives, see Using Custom Directives.

<!--
@resolveName
<true|false|1|0>
-->
Default (if not specified): true

struct UnresolvedPrimitiveStruct {
PrimitiveStruct primitive_member;
//@resolve-name false
};

<xsd:complexType name="UnresolvedPrimitiveStruct">
<xsd:sequence>
<xsd:element name="primitive_member"
minOccurs="1" maxOccurs="1"
type="PrimitiveStruct"/>
<!-- @resolveName false --> </xsd:sequence>
</xsd:complexType>

top-level directive6 Directives are RTI extensions to the standard IDL grammar. For additional information about directives, see Using Custom Directives.

<!--
@topLevel <true|false|1|0>
-->
Default (if not specified): true

struct TopLevelPrimitiveStruct {
short short_member;
}; //@top-level false

<xsd:complexType name="TopLevelPrimitiveStruct"> <xsd:sequence> <xsd:element name="short_member"
minOccurs="1" maxOccurs="1"
type="xsd:short"/>
</xsd:sequence>
</xsd:complexType> <!-- @topLevel false -->

other directives

<!--
@<directive kind>
<value>
-->

//@copy This text will be copied in the generated files

<!--@copy This text will be copied in the generated files -->

enum

xsd:simpleType with
enumeration

enum PrimitiveEnum {
ENUM1,
ENUM2,
ENUM3
};

enum PrimitiveEnum {
ENUM1 = 10,
ENUM2 = 20,
ENUM3 = 30
};

<xsd:simpleType name="PrimitiveEnum"> <xsd:restriction base="xsd:string"> <xsd:enumeration value="ENUM1"/> <xsd:enumeration value="ENUM2"/> <xsd:enumeration value="ENUM3"/> </xsd:restriction> </xsd:simpleType> <xsd:simpleType name="PrimitiveEnum"> <xsd:restriction base="xsd:string"> <xsd:enumeration value="ENUM1"> <xsd:annotation> <xsd:appinfo> <ordinal>10</ordinal> </xsd:appinfo> </xsd:annotation> </xsd:enumeration> <xsd:enumeration value="ENUM2"> <xsd:annotation> <xsd:appinfo> <ordinal>20</ordinal> </xsd:appinfo> </xsd:annotation> </xsd:enumeration> <xsd:enumeration value="ENUM3"> <xsd:annotation> <xsd:appinfo> <ordinal>30</ordinal> </xsd:appinfo> </xsd:annotation> </xsd:enumeration> </xsd:restriction> </xsd:simpleType>

constant

IDL constants are mapped by substituting their value directly in the generated file

struct

xsd:complexType
with xsd:sequence

struct PrimitiveStruct { short short_member; };

<xsd:complexType name="PrimitiveStruct">
<xsd:sequence>
<xsd:element name="short_member"
minOccurs="1" maxOccurs="1" type="xsd:short"/> </xsd:sequence>
</xsd:complexType>

union

xsd:complexType
with xsd:choice

union PrimitiveUnion
switch (long) {
case 1:
short short_member;
default:
long long_member; };

<xsd:complexType name="PrimitiveUnion"> <xsd:sequence> <xsd:element name="discriminator" type="xsd:int"/> <xsd:choice> <!-- case 1 -->7 The discriminant values can be described using comments (as specified by the standard) or xsd:annotation tags. We recommend using annotations because comments may be removed by XSD/XML parsers. <xsd:element name="short_member"
minOccurs="0" maxOccurs="1"
type="xsd:short"> <xsd:annotation> <xsd:appinfo> <case>1</case> </xsd:appinfo> </xsd:annotation> </xsd:element> <!-- case default --> <xsd:element name="long_member"
minOccurs="0" maxOccurs="1"
type="xsd:int"> <xsd:annotation> <xsd:appinfo> <case>default</case> </xsd:appinfo> </xsd:annotation> </xsd:element> </xsd:choice> </xsd:sequence> </xsd:complexType>

valuetype

xsd:complexType
with @valuetype directive

valuetype BaseValueType {
public long long_member; }; valuetype DerivedValueType: BaseValueType { public long long_member2; public long long_member3; };

<xsd:complexType name="BaseValueType"> <xsd:sequence>
<xsd:element name=”long_member"
maxOccurs="1" minOccurs="1"
type="xs:int"/> <!-- @visibility public --> </xsd:sequence> </xs:complexType> <!-- @valuetype true --> <xs:complexType name="DerivedValueType">
<xs:complexContent>
<xs:extension base="BaseValueType">
<xs:sequence>
<xs:element name= "long_member2"
maxOccurs="1" minOccurs="1"
type="xs:int"/>
<!-- @visibility public -->
<xs:element name= "long_member3"
maxOccurs="1" minOccurs="1"
type="xs:int"/>
<!-- @visibility public -->
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<!-- @valuetype true -->

typedef

Type definitions are
mapped to XML schema
type restrictions

typedef short ShortType; struct PrimitiveStruct { short short_member; }; typedef PrimitiveType = PrimitiveStructType;

<xsd:simpleType name="ShortType"> <xsd:restriction base="xsd:short"/> </xsd:simpleType> <!—- Struct definition --> <xsd:complexType name="PrimitiveStruct">
<xsd:sequence>
<xsd:element name="short_member"
minOccurs="1" maxOccurs="1"
type="xsd:short"/> </xsd:sequence>
</xsd:complexType> <!—- Typedef definition --> <xsd:complexType
name="PrimitiveTypeStructType">
<xsd:complexContent>
<xsd:restriction base=”PrimitiveStruct”>
<xsd:sequence>
<xsd:element name="short_member"
minOccurs="1" maxOccurs="1"
type="xsd:short"/>
</xsd:sequence>
</xsd:restriction> </xsd:complexContent> </xsd:complexType>

arrays

n xsd:complexType with
sequence containing one
element with
min & max occurs

There is one xsd:complexType
per array dimension

struct OneArrayStruct { short short_array[2]; };

<!-- Array type --> <xsd:complexType name="OneArrayStruct_short_array_ArrayOfShort"> <xsd:sequence> <xsd:element name="item" minOccurs="2" maxOccurs="2" type="xsd:short"> </xsd:element> </xsd:sequence> </xsd:complexType> <!-- Struct w unidimensional array member --> <xsd:complexType name="OneArrayStruct"> <xsd:sequence> <xsd:element name="short_array" minOccurs="1" maxOccurs="1" type= "OneArrayStruct_short_array_ArrayOfShort"/> </xsd:sequence> </xsd:complexType>

arrays (cont’d)

n xsd:complexType with
sequence containing one
element with min & max
occurs

There is one
xsd:complexType per array dimension

struct TwoArrayStruct { short short_array[2][1]; };

<!--Second dimension array type --> <xsd:complexType name= "TwoArrayStruct_short_array_ArrayOfShort"> <xsd:sequence> <xsd:element name="item" minOccurs="2" maxOccurs="2" type="xsd:short"> </xsd:element> </xsd:sequence> </xsd:complexType> <!-- First dimension array type --> <xsd:complexType name= "TwoArrayStruct_short_array_ArrayOfArrayOfShort"> <xsd:sequence> <xsd:element name="item" minOccurs="1" maxOccurs="1"
type=
"TwoArrayStruct_short_array_ArrayOfShort"> </xsd:element> </xsd:sequence> </xsd:complexType> <!--Struct containing a bidimensional array
member --> <xsd:complexType name="TwoArrayStruct"> <xsd:sequence> <xsd:element name="short_array" minOccurs="1" maxOccurs="1" type= "TwoArrayStruct_short_array_ArrayOfArrayOfShort"/> </xsd:sequence> </xsd:complexType>

bounded sequence

xsd:complexType with
sequence containing one element
with min & max occurs

struct SequenceStruct {
sequence<short,4>
short_sequence; };

<!-- Sequence type -->
<xsd:complexType name= "SequenceStruct_short_sequence_SequenceOfShort">
<xsd:sequence>
<xsd:element name="item" minOccurs="0"
maxOccurs="4" type="xsd:short">
</xsd:element>
</xsd:sequence>
</xsd:complexType> <!-- Struct containing a bounded sequence
member --> <xsd:complexType name="SequenceStruct"> <xsd:sequence> <xsd:element name="short_sequence" minOccurs="1" maxOccurs="1" type= "SequenceStruct_short_sequence_SequenceOfShort"/> </xsd:sequence> </xsd:complexType>

unbounded sequence

xsd:complexType with sequence
containing one element with
min & max occurs

struct SequenceStruct {
sequence<short> short_sequence; };

<!-- Sequence type --> <xsd:complexType name= "SequenceStruct_short_sequence_SequenceOfShort"> <xsd:sequence> <xsd:element name="item"
minOccurs="0" maxOccurs="unbounded"
type="xsd:short"/> </xsd:sequence> </xsd:complexType> <!-- Struct containing unbounded sequence member --> <xsd:complexType name="SequenceStruct"> <xsd:sequence> <xsd:element name="short_sequence" minOccurs="1" maxOccurs="1"
type= "SequenceStruct_short_sequence_SequenceOfShort"/> </xsd:sequence> </xsd:complexType>

array of sequences

n + 1 xsd:complexType with
sequence containing one element
with min & max occurrences.

There is one xsd:complexType per
array dimension and one
xsd:complexType for the sequence.

struct ArrayOfSequencesStruct { sequence<short,4> sequence_sequence[2]; };

<!-- Sequence declaration -->
<xsd:complexType name=
"ArrayOfSequencesStruct_sequence_array_SequenceOfShort">
<xsd:sequence>
<xsd:element name="item"
minOccurs="0" maxOccurs="4"
type="xsd:short">
</xsd:element>
</xsd:sequence>
</xsd:complexType>

<!-- Array declaration -->
<xsd:complexType name=
"ArrayOfSequencesStruct_sequence_array_ArrayOf
SequenceOfShort"> <xsd:sequence> <xsd:element name="item" minOccurs="2" maxOccurs="2" type= "ArrayOfSequencesStruct_sequence_array_SequenceOfShort"> </xsd:element> </xsd:sequence> </xsd:complexType> <!-- Structure containing a member that is an array of sequences --> <xsd:complexType name="ArrayOfSequencesStruct"> <xsd:sequence> <xsd:element name="sequence_array" minOccurs="1" maxOccurs="1" type= "ArrayOfSequencesStruct_sequence_array_ArrayOf
SequenceOfShort"/> </xsd:sequence> </xsd:complexType>

sequence of arrays

Sequences of arrays must be
implemented using an explicit
type definition (typedef) for
the array

typedef short ShortArray[2]; struct SequenceOfArraysStruct { sequence<ShortArray,2> arrays_sequence; };

<!-- Array declaration -->
<xsd:complexType name="ShortArray">
<xsd:sequence> <xsd:element name="item" minOccurs="2" maxOccurs="2"
type="xsd:short"> </xsd:element> </xsd:sequence> </xsd:complexType> <!-- Sequence declaration --> <xsd:complexType name= "SequencesOfArraysStruct_array_sequence_SequenceOfShortArray"> <xsd:sequence>
<xsd:element name="item" minOccurs="0" maxOccurs="2" type="ShortArray"> </xsd:element> </xsd:sequence>
</xsd:complexType>

<!-- Struct containing a sequence of arrays -->
<xsd:complexType name="SequenceOfArraysStruct">
<xsd:sequence>
<xsd:element name="arrays_sequence"
minOccurs="1" maxOccurs="1" type=
"SequencesOfArraysStruct_arrays_sequence_SequenceOfShortArray"/>
</xsd:sequence>
</xsd:complexType>

sequence of sequences

Sequences of sequences must
be implemented using an
explicit type definition (typedef)
for the second sequence

typedef sequence<short,4> ShortSequence; struct SequenceOfSequences {
sequence<ShortSequence, 2> sequences_sequence;
};

<!-- Internal sequence declaration --> <xsd:complexType name="ShortSequence"> <xsd:sequence> <xsd:element name="item" minOccurs="0" maxOccurs="4" type="xsd:short"> </xsd:element> </xsd:sequence> </xsd:complexType> <!-- External sequence declaration -->
<xsd:complexType name=
"SequencesOfSequences_sequences_sequence_SequenceOfShortSequence"> <xsd:sequence> <xsd:element name="item"
minOccurs="0" maxOccurs="2" type="ShortSequence"> </xsd:element> </xsd:sequence> </xsd:complexType> <!--Struct containing a sequence of sequences --> <xsd:complexType name="SequenceOfSequences"> <xsd:sequence> <xsd:element name="sequences_sequence" minOccurs="1" maxOccurs="1" type="SequencesOfSequences_ sequences_sequence_SequenceOfShortSequence"/> </xsd:sequence> </xsd:complexType>

module

Modules are mapped adding the
name of the module before the
name of each type inside the module

module PackageName { struct PrimitiveStruct { long long_member; };
};

<xsd:complexType name=
"PackageName.PrimitiveStruct"> <xsd:sequence> <xsd:element name="long_member"
minOccurs="1" maxOccurs="1"
type="xsd:int"/>
</xsd:sequence> </xsd:complexType>

include

xsd:include

#include "PrimitiveType.idl"

<xsd:include schemaLocation=
"PrimitiveType.xsd"/>

© 2016 RTI