Skip to content

XML encoding of "null" Variant is incorrect #3056

Description

@kevinherron

Type of issue

  • Bug
  • Enhancement
  • Compliance
  • Question
  • Help wanted

Current Behavior

The way XmlEncoder encodes a "null" Variant value is incorrect.

A Variant value is encoded as an xs:complexType with 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>

Which means the expected output for something like:

var context = new ServiceMessageContext();
string actualXmlValue;

using (IEncoder xmlEncoder = new XmlEncoder(context))
{
    Variant value = Variant.Null;

    xmlEncoder.PushNamespace(Namespaces.OpcUaXsd);
    xmlEncoder.WriteVariant("Test", value);
    xmlEncoder.PopNamespace();
    actualXmlValue = xmlEncoder.CloseAndReturnText();
}

would be some variation of:

<Test xmlns:uax="http://opcfoundation.org/UA/2008/02/Types.xsd"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <uax:Value xsi:nil="true" />
</Test>

yet the implementation of XmlEncoder yields this:

<Test xmlns="http://opcfoundation.org/UA/2008/02/Types.xsd">
  <Value>
    <Null />
  </Value>
</Test>

Ignore the namespaces and prefixes - the problem is the element named "Null" for which a reference does not exist in either Part 6 nor the the schema defined by http://opcfoundation.org/UA/2008/02/Types.xsd.

I believe another valid encoding based on the schema includes:

<Test>
  <Value></Value>
</Test>

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

complianceAn issue was found which is not compliant with the OPC UA specification.

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions