Most built-in types are encoded in XML using the formats defined in XML Schema Part 2specification. Any special restrictions or usages are discussed below. Some of the built-in types have an XML Schema defined for them using the syntax defined in XML Schema Part 2.

The prefix xs:is used to denote a symbol defined by the XML Schema specification.

A Boolean value is encoded as an xs:booleanvalue.

Integer values are encoded using one of the subtypes of the xs:decimaltype. The mappings between the OPC UA integer types and XML schema data types are shown in Table 18.

Table 18– XML Data Type Mappings for Integers

Name

XML Type

SByte

xs:byte

Byte

xs:unsignedByte

Int16

xs:short

UInt16

xs:unsignedShort

Int32

xs:int

UInt32

xs:unsignedInt

Int64

xs:long

UInt64

xs:unsignedLong

Floating point values are encoded using one of the XML floating point types. The mappings between the OPC UA floating point types and XML schema data types are shown in Table 19.

Table 19– XML Data Type Mappings for Floating Points

Name

XML Type

Float

xs:float

Double

xs:double

The XML floating point type supports positive infinity (INF), negative infinity (-INF) and not-a-number (NaN).

A Stringvalue is encoded as an xs:stringvalue.

A DateTimevalue is encoded as an xs:dateTimevalue.

All DateTime values shall be encoded as UTC times or with the time zone explicitly specified.

Correct:

2002-10-10T00:00:00+05:00

2002-10-09T19:00:00Z

Incorrect:

2002-10-09T19:00:00

It is recommended that all xs:dateTimevalues be represented in UTC format.

The earliest and latest date/time values that can be represented on a DevelopmentPlatformhave special meaning and shall not be literally encoded in XML.

The earliest date/time value on a DevelopmentPlatformshall be encoded in XML as '0001-01-01T00:00:00Z'.

The latest date/time value on a DevelopmentPlatformshall be encoded in XML as '9999-12-31T23:59:59Z'

If a decoder encounters a xs:dateTimevalue that cannot be represented on the DevelopmentPlatformit should convert the value to either the earliest or latest date/time that can be represented on the DevelopmentPlatform. The XML decoder should not generate an error if it encounters an out of range date value.

The earliest date/time value on a DevelopmentPlatformis equivalent to a null date/time value.

A Guidis encoded using the string representation defined in 5.1.3.

The XML schema for a Guidis:

<xs:complexType name="Guid">

<xs:sequence>

<xs:element name="String" type="xs:string" minOccurs="0" />

</xs:sequence>

</xs:complexType>

A ByteStringvalue is encoded as an xs:base64Binaryvalue (see Base64).

The XML schema for a ByteString is:

<xs:element name="ByteString" type="xs:base64Binary" nillable="true"/>

An XmlElementvalue is encoded as an xs:complexTypewith the following XML schema:

<xs:complexType name="XmlElement">

<xs:sequence>

<xs:any minOccurs="0" maxOccurs="1" processContents="lax" />

</xs:sequence>

</xs:complexType>

XmlElements may only be used inside Variantor ExtensionObjectvalues.

A NodeIdvalue is encoded as an xs:string with the syntax:

ns=<namespaceindex>;<type>=<value>

The elements of the syntax are described in Table 20.

Table 20– Components of NodeId

Field

Data Type

Description

<namespaceindex>

UInt16

The NamespaceIndexformatted as a base 10 number.

If the index is 0 then the entire 'ns=0;' clause shall be omitted.

<type>

Enumeration

A flag that specifies the IdentifierType.

The flag has the following values:

i

NUMERIC (UInt32)

s

STRING (String)

g

GUID (Guid)

b

OPAQUE (ByteString)

<value>

*

The Identifierencoded as string.

The Identifieris formatted using the XML data type mapping for the IdentifierType.

Note that the Identifiermay contain any non-null UTF-8character including whitespace.

Examples of NodeIds:

i=13

ns=10;i=-1

ns=10;s=Hello:World

g=09087e75-8e5e-499b-954f-f2a9603db28a

ns=1;b=M/RbKBsRVkePCePcx24oRA==

The XML schema for a NodeIdis:

<xs:complexType name="NodeId">

<xs:sequence>

<xs:element name="Identifier" type="xs:string" minOccurs="0" />

</xs:sequence>

</xs:complexType>

An ExpandedNodeId value is encoded as an xs:string with the syntax:

svr=<serverindex>;ns=<namespaceindex>;<type>=<value>

or

svr=<serverindex>;nsu=<uri>;<type>=<value>

The possible fields are shown in Table 21.

Table 21– Components of ExpandedNodeId

Field

Data Type

Description

<serverindex>

UInt32

The ServerIndexformatted as a base 10 number.

If the ServerIndexis 0 then the entire 'svr=0;' clause shall be omitted.

<namespaceindex>

UInt16

The NamespaceIndexformatted as a base 10 number.

If the NamespaceIndexis 0 then the entire 'ns=0;' clause shall be omitted.

The NamespaceIndexshall not be present if the URI is present.

<uri>

String

The NamespaceUriformatted as a string.

Any reserved characters in the URI shall be replaced with a ‘%’ followed by its 8 bit ANSI value encoded as two hexadecimal digits (case insensitive). For example, the character ‘;’ would be replaced by ‘%3B’.

The reserved characters are ‘;’ and ‘%’.

If the NamespaceUriis null or empty, then 'nsu=;' clause shall be omitted.

<type>

Enumeration

A flag that specifies the IdentifierType.

This field is described in Table 20.

<value>

*

The Identifier encoded as string.

This field is described in Table 20.

The XML schema for an ExpandedNodeIdis:

<xs:complexType name="ExpandedNodeId">

<xs:sequence>

<xs:element name="Identifier" type="xs:string" minOccurs="0" />

</xs:sequence>

</xs:complexType>

A StatusCode is encoded as an xs:unsignedIntwith the following XML schema:

<xs:complexType name="StatusCode">

<xs:sequence>

<xs:element name="Code" type="xs:unsignedInt" minOccurs="0" />

</xs:sequence>

</xs:complexType>

An DiagnosticInfo value is encoded as an xs:complexTypewith the following XML schema:

<xs:complexType name="DiagnosticInfo">

<xs:sequence>

<xs:element name="SymbolicId" type="xs:int" minOccurs="0" />

<xs:element name="NamespaceUri" type="xs:int" minOccurs="0" />

<xs:element name="Locale" type="xs:int" minOccurs="0/>

<xs:element name="LocalizedText" type="xs:int" minOccurs="0/>

<xs:element name="AdditionalInfo" type="xs:string" minOccurs="0"/>

<xs:element name="InnerStatusCode" type="tns:StatusCode"

minOccurs="0" />

<xs:element name="InnerDiagnosticInfo" type="tns:DiagnosticInfo"

minOccurs="0" />

</xs:sequence>

</xs:complexType>

DiagnosticInfo allows unlimited nesting which could result in stack overflow errors even if the message size is less than the maximum allowed. Decoders shall support at least 100 nesting levels. Decoders shall report an error if the number of nesting levels exceeds what it supports.

A QualifiedNamevalue is encoded as an xs:complexTypewith the following XML schema:

<xs:complexType name="QualifiedName">

<xs:sequence>

<xs:element name="NamespaceIndex" type="xs:int" minOccurs="0" />

<xs:element name="Name" type="xs:string" minOccurs="0" />

</xs:sequence>

</xs:complexType>

A LocalizedTextvalue is encoded as an xs:complexTypewith the following XML schema:

<xs:complexType name="LocalizedText">

<xs:sequence>

<xs:element name="Locale" type="xs:string" minOccurs="0" />

<xs:element name="Text" type="xs:string" minOccurs="0" />

</xs:sequence>

</xs:complexType>

An ExtensionObject value is encoded as an xs:complexTypewith the following XML schema:

<xs:complexType name="ExtensionObject">

<xs:sequence>

<xs:element name="TypeId" type="tns:NodeId" minOccurs="0" />

<xs:element name="Body" minOccurs="0">

<xs:complexType>

<xs:sequence>

<xs:any minOccurs="0" processContents="lax"/>

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:sequence>

</xs:complexType>

The body of the ExtensionObject contains a single element which is either a ByteStringor XML encoded Structure. A decoder can distinguish between the two by inspecting the top-level element. An element with the name tns:ByteString contains an OPC UA Binary encoded body. Any other name shall contain an OPC UA XML encoded body. The TypeIdspecifies the syntax of a ByteStringbody which could be UTF-8 encoded JSON, UA Binary or some other format.

The TypeIdis the NodeIdfor the DataTypeEncoding Object.

A Variant value is encoded as an xs:complexTypewith the following XML schema:

<xs:complexType name="Variant">

<xs:sequence>

<xs:element name="Value" minOccurs="0" nillable="true">

<xs:complexType>

<xs:sequence>

<xs:any minOccurs="0" processContents="lax"/>

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:sequence>

</xs:complexType>

If the Variantrepresents a scalar value, then it shall contain a single child element with the name of the built-in type. For example, the single precision floating point value 3,141 5 would be encoded as:

<tns:Float>3.1415</tns:Float>

If the Variantrepresents a single dimensional array, then it shall contain a single child element with the prefix 'ListOf' and the name built-in type. For example, an Arrayof strings would be encoded as:

<tns:ListOfString>

<tns:String>Hello</tns:String>

<tns:String>World</tns:String>

</tns:ListOfString>

If the Variantrepresents a multidimensional Array,then it shall contain a child element with the name ‘Matrix’with the two sub-elements shown in this example:

<tns:Matrix>

<tns:Dimensions>

<tns:Int32>2</tns:Int32>

<tns:Int32>2</tns:Int32>

</tns:Dimensions>

<tns:Elements>

<tns:String>A</tns:String>

<tns:String>B</tns:String>

<tns:String>C</tns:String>

<tns:String>D</tns:String>

</tns:Elements>

</tns:Matrix>

In this example, the array has the following elements:

[0,0] = "A"; [0,1] = "B"; [1,0] = "C"; [1,1] = "D"

The elements of a multi-dimensional Arrayare always flattened into a single dimensional Arraywhere the higher rank dimensions are serialized first. This single dimensional Arrayis encoded as a child of the ‘Elements’ element. The ‘Dimensions’ element is an Arrayof Int32values that specify the dimensions of the array starting with the lowest rank dimension. The multi-dimensional Arraycan be reconstructed by using the dimensions encoded. All dimensions shall be specified and shall be greater than zero. If the dimensions are inconsistent with the number of elements in the array, then the decoder shall stop and raise a Bad_DecodingError.

The complete set of built-in type names is found in Table 1.

A DataValuevalue is encoded as a xs:complexTypewith the following XML schema:

<xs:complexType name="DataValue">

<xs:sequence>

<xs:element name="Value" type="tns:Variant" minOccurs="0"

nillable="true" />

<xs:element name="StatusCode" type="tns:StatusCode"

minOccurs="0" />

<xs:element name="SourceTimestamp" type="xs:dateTime"

minOccurs="0" />

<xs:element name="SourcePicoseconds" type="xs:unsignedShort"

minOccurs="0"/>

<xs:element name="ServerTimestamp" type="xs:dateTime"

minOccurs="0" />

<xs:element name="ServerPicoseconds" type="xs:unsignedShort"

minOccurs="0"/>

</xs:sequence>

</xs:complexType>

A DecimalValue is a encoded as an xs:complexType wit the following XML schema:

<xs:complexType name="Decimal">

<xs:sequence>

<xs:element name="TypeId" type="tns:NodeId" minOccurs="0" />

<xs:element name="Body" minOccurs="0">

<xs:complexType>

<xs:sequence>

<xs:element name="Scale" type="xs:unsignedShort" />

<xs:element name="Value" type="xs:string" />

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:sequence>

</xs:complexType>

The NodeIdis always the NodeIdof the Decimal DataType. When encoded in a Variantthe Decimalis encoded as an ExtensionObject. Arrays of Decimalsare Arraysof ExtensionObjects.

The Valueis a base-10 signed integer with no limit on size. See 5.1.7for a description of the Scaleand Valuefields.

Enumerationsthat are used as parameters in the Messagesdefined in OPC 10000-4are encoded as xs:stringwith the following syntax:

<symbol>_<value>

The elements of the syntax are described in Table 22.

Table 22– Components of Enumeration

Field

Type

Description

<symbol>

String

The symbolic name for the enumerated value.

<value>

UInt32

The numeric value associated with enumerated value.

For example, the XML schema for the NodeClassenumeration is:

<xs:simpleType name="NodeClass">

<xs:restriction base="xs:string">

<xs:enumeration value="Unspecified_0" />

<xs:enumeration value="Object_1" />

<xs:enumeration value="Variable_2" />

<xs:enumeration value="Method_4" />

<xs:enumeration value="ObjectType_8" />

<xs:enumeration value="VariableType_16" />

<xs:enumeration value="ReferenceType_32" />

<xs:enumeration value="DataType_64" />

<xs:enumeration value="View_128" />

</xs:restriction>

</xs:simpleType>

Enumerationsthat are stored in a Variantare encoded as an Int32value.

For example, any Variablecould have a value with a DataTypeof NodeClass. In this case, the corresponding numeric value is placed in the Variant(e.g. NodeClass Objectwould be stored as a 1).

One dimensionalArrayparameters are always encoded by wrapping the elements in a container element and inserting the container into the structure. The name of the container element should be the name of the parameter. The name of the element in the array shall be the type name.

For example, the Readservice takes an array of ReadValueIds. The XML schema would look like:

<xs:complexType name="ListOfReadValueId">

<xs:sequence>

<xs:element name="ReadValueId" type="tns:ReadValueId"

minOccurs="0" maxOccurs="unbounded" nillable="true" />

</xs:sequence>

</xs:complexType>

The nillable attribute shall be specified because XML encoders will drop elements in arrays if those elements are empty.

Multi-dimensional Arrayparameters are encoded using the Matrixtype defined in 5.3.1.17.

Structures are encoded as a xs:complexTypewith all of the fields appearing in a sequence. All fields are encoded as an xs:element. All elements have minOccurs set 0 to allow for compact XML representations. If an element is missing the default value for the field type is used. If the field type is a structure the default value is an instance of the structure with default values for each contained field.

Types which have a NULL value defined shall have the nillable="true" flag set.

For example, the Read service has a ReadValueIdstructure in the request. The XML schema would look like:

<xs:complexType name="ReadValueId">

<xs:sequence>

<xs:element name="NodeId" type="tns:NodeId"

minOccurs="0" nillable="true" />

<xs:element name="AttributeId" type="xs:int" minOccurs="0" />

<xs:element name="IndexRange" type="xs:string"

minOccurs="0" nillable="true" />

<xs:element name="DataEncoding" type="tns:NodeId"

minOccurs="0" nillable="true" />

</xs:sequence>

</xs:complexType>

Structureswith optional fields are encoded as a xs:complexTypewith all of the fields appearing in a sequence. The first element is a bit mask that specifies what fields are encoded. The bits in the mask are sequentially assigned to optional fields in the order they appear in the Structure.

To allow for compact XML, any field can be omitted from the XML so decoders shall assign default values based on the field type for any mandatory fields.

For example, the following Structurehas one mandatory and two optional fields. The XML schema would look like:

<xs:complexType name="OptionalType">

<xs:sequence>

<xs:element name="EncodingMask" type="xs:unsignedLong" />

<xs:element name="X" type="xs:int" minOccurs="0" />

<xs:element name="O1" type="xs:int" minOccurs="0" />

<xs:element name="Y" type="xs:byte" minOccurs="0" />

<xs:element name="O2" type="xs:int" minOccurs="0" />

</xs:sequence>

</xs:complexType>

In the example above, the EncodingMask has a value of 3 if both O1 and O2 are encoded. Encoders shall set unused bits to 0 and decoders shall ignore unused bits.

If a Structurewith optional fields is subtyped, the subtypes extend the EncodingMaskdefined for the the parent.

Unions are encoded as a xs:complexTypecontaining a xs:sequencewith two entries.

The first entry in the sequence is the SwitchField xs:elementand specifies a numeric value which identifies which element in the xs:choice is encoded. The name of element may be any valid text.

The second entry in the sequence is an xs:choice which specifies the possible fields. The order in the xs:choice determines the value of the SwitchField when that choice is encoded. The first element has a SwitchField valueof 1 and the last value has a SwitchField equal to the number of choices.

No additional elements in the sequence are permitted. If the SwitchField is missing or 0 then the union has a NULL value.Encoders or decoders shall report an error for any SwitchFieldvalue greater than the number of defined union fields.

For example, the following union has two fields. The XML schema would look like:

<xs:complexType name="Type1">

<xs:sequence>

<xs:element name="SwitchField"

type="xs:unsignedInt" minOccurs="0"/>

<xs:choice>

<xs:element name="Field1" type="xs:int" minOccurs="0"/>

<xs:element name="Field2" type="tns:Field2" minOccurs="0"/> </xs:choice>

</xs:sequence>

</xs:complexType>

Messagesare encoded as an xs:complexType. The parameters in each Message are serialized in the same way the fields of a Structureare serialized.