The goal of the mapping is to provide a lossless, bi-directional mapping of built-in data types from OPC UA to XML and vice versa.

  • In some cases, it is possible to map an OPC UA DataType to an XML data type directly (see 5.2). In most cases, this is a lossless mapping, sometimes there is a loss of precision or information.
  • In other cases, there is an OPC UA DataType without a corresponding XML data type. For those cases, the XML Schema defined in OPC 10000-6, Annex D, provides appropriate XML data types that can be used. The mapping to those XML data types is defined in 5.3.
  • Finally, there are cases where there is an XML data type without a corresponding OPC UA DataType. For those cases, an OPC UA Information Model is defined (see 6). The mapping is defined in 5.4.

In Table 12, the direct mapping of XML data types and OPC UA DataTypes is defined. If there are any restrictions on a lossless, bidirectional mapping, this is described in the Comment column. If this column is empty, there are no restrictions.

Table 12 – Mapping of DataTypes

OPC UA DataType

XML DataType

Comment

String

string

Implementations might limit the maximum String size.

Boolean

boolean

Decimal

decimal

Implementations might limit the maximum Decimal size.

Float

float

Double

double

Duration

duration

In this mapping there might be a loss in precision (XML only requires down to minimum fractional second precision of milliseconds, OPC UA based Duration is a double (representing milliseconds).

DateTime

dateTime

Many implementations will not be able to represent the full range of DateTime values. To maximize interoperability, the following rules apply:

When going from XML to an implementation:

  • If the XML value is <= MinDate then the value is MinDate;
  • If the XML value is >= MaxDate then the value is MaxDate;
  • XML values without a TimezoneOffset are assumed to be in UTC;
  • XML values with a TimezoneOffset are converted to UTC;
  • Fractions of seconds not supported by the implementation are dropped.

When going from an implementation to XML:

  • If the value is MinDate the XML is ‘0001-01-01T00:00:00Z’;
  • If the value is MaxDate the XML is ‘9999-12-31T23:59:59Z’;
  • XML values are always in UTC;
  • Fractions of seconds, if supported by the implementation, are included.

Where:

  • MinDate is the earliest date supported by an implementation;
  • MaxDate is the latest date supported by an implementation;
  • All implementations are required to support seconds.

The value of MinDate is the default value and semantically equivalent to a Null value.

UtcTime

dateTimeTimestamp

See limitations of DateTime

ByteString

base64Binary

XML has two ByteString representations – hexBinary and base64Binary. The mapping of OPC UA ByteString to XML base64Binary is defined in OPC 10000-6. The mapping to XML hexBinary is defined in section 5.4.

Implementations might limit the maximum ByteString size.

Int64

long

Int32

int

Int16

short

SByte

byte

UInt64

unsignedLong

UInt32

unsignedInt

UInt16

unsignedShort

Byte

unsignedByte

NormalizedString

normalizedString

Implementations might limit the maximum String size.

In OPC UA, limitations on the string are only defined in the specification but not explicitly defined by the data structure, so implementations not following the specification may provide invalid values.

LocaleId

language

Both data types are based on strings defined in IETF RFC 5646 and should represent the same format, e.g., “en-US”.

OPC UA allows an empty or null string, which is not allowed in XML.

In OPC UA, limitations on the string are only defined in the specification but not explicitly defined by the data structure, so implementations not following the specification may provide invalid values.

In XML, the schema definition only restricts the allowed values to a certain degree, so implementations not following the specification may provide invalid values.

XML only restricts the allowed values to a certain degree in its schema definition, so potentially values could be invalid.

UriString

anyURI

Implementations might limit the maximum String size.

In Table 13, the mapping of built-in OPC UA DataTypes to XML data types is defined, where there is no corresponding built-in XML data type available. An XML Schema defined in OPC 10000-6, Annex D, provides the appropriate XML data types for this mapping.

Table 13 – New XML DataType

OPC UA DataType

XML DataType

Comment

DataValue

DataValue

XML data type defined in OPC 10000-6, Annex D

DiagnosticInfo

DiagnosticInfo

XML data type defined in OPC 10000-6, Annex D

ExpandedNodeId

ExpandedNodeId

XML data type defined in OPC 10000-6, Annex D

Contains ServerIndex and potentially NamespaceIndex (both Server-specific)

Guid

Guid

XML data type defined in OPC 10000-6, Annex D

Does not check specific GUID-format in XML

LocalizedText

LocalizedText

XML data type defined in OPC 10000-6, Annex D

NodeId

NodeId

XML data type defined in OPC 10000-6, Annex D

Contains NamespaceIndex (Server-specific)

QualifiedName

QualifiedName

XML data type defined in OPC 10000-6, Annex D

Contains NamespaceIndex (Server-specific)

StatusCode

StatusCode

XML data type defined in OPC 10000-6, Annex D

XmlElement

XmlElement

XML data type defined in OPC 10000-6, Annex D

In Table 14, the mapping of built-in XML data types to OPC UA DataTypes is defined, where there is no corresponding built-in OPC UA DataType available. Those OPC UA DataTypes are defined in 6. In some cases, the range is smaller than possible in the XML data type.

Table 14 – New OPC UA DataTypes

OPC UA DataType

XML DataType

Comment

XmlQName

QName

Contains XML document specific prefix

Implementations might limit the maximum String size.

Array of XmlQName

NOTATION

Contains XML document specific prefixes

Implementations might limit the maximum String size.

XmlToken

token

Implementations might limit the maximum String size.

XmlNmToken

NMTOKEN

Implementations might limit the maximum String size.

Array of XmlNmToken

NMTOKENS

Implementations might limit the maximum array length.

XmlName

Name

Implementations might limit the maximum String size.

XmlNcName

NCName

Implementations might limit the maximum String size.

XmlId

ID

Implementations might limit the maximum String size.

XmlIdRef

IDREF

Implementations might limit the maximum String size.

Array of XmlIdRef

IDREFS

Implementations might limit the maximum array length.

XmlEntity

ENTITY

Implementations might limit the maximum String size.

Array of XmlEntity

ENTITIES

Implementations might limit the maximum array length.

XmlInteger

integer

XmlInteger is a subtype of Int64 with a limited max. and min. value, whereas the size of integer is unlimited.

XmlNonPositiveInteger

nonPositiveInteger

The min. of XmlNonPositiveInteger is limited to min. of Int64, whereas the min. of nonPositiveInteger is unlimited.

XmlNegativeInteger

negativeInteger

The min. of XmlNegativeInteger is limited to min. of Int64, whereas the min. of negativeInteger is unlimited.

XmlNonNegativeInteger

nonNegativeInteger

The max. of XmlNonNegativeInteger is limited to max. of UInt64, whereas the max. of nonNegativeInteger is unlimited.

XmlPositiveInteger

positiveInteger

The max. of XmlPositiveInteger is limited to max. of UInt64, whereas the max. of positiveInteger is unlimited.

XmlHexBinary

hexBinary

Implementations might limit the maximum ByteString size.

XmlYearMonthDuration

yearMonthDuration

Implementations might limit the maximum String size.

XmlGYearMonth

gYearMonth

Implementations might limit the maximum String size.

XmlDayTimeDuration

dayTimeDuration

Implementations might limit the maximum String size.

XmlGYear

gYear

Implementations might limit the maximum String size.

XmlGMonth

gMonth

Implementations might limit the maximum String size.

XmlGDay

gDay

Implementations might limit the maximum String size.

XmlGMonthDay

gMonthDay

Implementations might limit the maximum String size.

XmlTime

time

Implementations might limit the maximum String size.

XmlDate

date

Implementations might limit the maximum String size.

If the concrete mapping of a data type does not specify more specific error handling rules, the following shall apply:

  • Return an error when the type conversion fails because of limitations in the destination range. In an OPC UA context, the StatusCode Bad_OutOfRange should be returned (e.g. in the Value of a Variable).
  • Return an error when an incorrect syntax is encountered. In an OPC UA context, the StatusCode Bad_SyntaxError should be returned (e.g. in the Value of a Variable).”