Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue with XML namespace schema while decoding an XML nodeset #1385

Merged
merged 2 commits into from
Apr 30, 2021

Conversation

SBaeumler
Copy link
Contributor

@SBaeumler SBaeumler commented Apr 28, 2021

  • added protected property XmlNamespace to BaseComplexType class
  • use XmlNamespace instead of TypeId.NamespaceUri for PushNamespace of
    encoder/decoder
  • adapt Encode/Decode method in OptionalFieldsComplexType and
    UnionComplexType class

Change was needed if Xml schema in Xml nodeset differ from the custom OPC UA namespace.
Only effects XML encoding and decoding from values of customized structured datatypes.

Example:

The OPC UA Namespace of the nodeset is http://MyTestOfExtensions but the xml namespace for the xml schema is http://MyTestOfExtensions/Types.xsd
These 2 namespaces are not forced to be equal, therefor the XmlDecoder need to Push the XmlNamespace for the schema to the Reader stack. Otherwise the ExtensionObject Body will not be read.

<?xml version="1.0" encoding="utf-8"?>
<UANodeSet LastModified="2021-04-08T11:57:22.286Z" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://opcfoundation.org/UA/2011/03/UANodeSet.xsd" xmlns:uax="http://opcfoundation.org/UA/2008/02/Types.xsd" xmlns:si="http://www.siemens.com/OPCUA/2017/SimaticNodeSetExtensions" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <NamespaceUris>
        <Uri>http://MyTestOfExtensions</Uri>
    </NamespaceUris>
    <Models>
        <Model ModelUri="http://MyTestOfExtensions" PublicationDate="2020-07-20T00:00:00Z" Version="1.00">
            <RequiredModel ModelUri="http://opcfoundation.org/UA/" PublicationDate="2020-07-15T00:00:00Z" Version="1.04.7"/>
        </Model>
    </Models>
    <Aliases>
        <Alias Alias="Boolean">i=1</Alias>
        <Alias Alias="DateTime">i=13</Alias>
        <Alias Alias="String">i=12</Alias>
        <Alias Alias="NodeId">i=17</Alias>
        <Alias Alias="QualifiedName">i=20</Alias>
        <Alias Alias="HasComponent">i=47</Alias>
        <Alias Alias="HasProperty">i=46</Alias>
        <Alias Alias="Organizes">i=35</Alias>
        <Alias Alias="HasSubtype">i=45</Alias>
        <Alias Alias="HasTypeDefinition">i=40</Alias>
        <Alias Alias="HasModellingRule">i=37</Alias>
        <Alias Alias="HasEncoding">i=38</Alias>
    </Aliases>
    <Extensions>
        <Extension>
            <si:Generator Product="SiOME" Edition="Standard" Version="2.2.3-beta24"/>
        </Extension>
        <Extension>
            <si:GeneratorExtension Hash="cee97a4b7b32c169214c2bbc22b555d2"/>
        </Extension>
    </Extensions>
    <UAObject SymbolicName="http___MyTestOfExtensions" NodeId="ns=1;i=5000" BrowseName="1:http://MyTestOfExtensions" ParentNodeId="i=11715">
        <DisplayName>http://MyTestOfExtensions</DisplayName>
        <References>
            <Reference ReferenceType="HasComponent" IsForward="false">i=11715</Reference>
            <Reference ReferenceType="HasTypeDefinition">i=11616</Reference>
        </References>
    </UAObject>
    <UAVariable DataType="String" NodeId="ns=1;i=6002" BrowseName="NamespaceUri" ParentNodeId="ns=1;i=5000">
        <DisplayName>NamespaceUri</DisplayName>
        <References>
            <Reference ReferenceType="HasProperty" IsForward="false">ns=1;i=5000</Reference>
            <Reference ReferenceType="HasTypeDefinition">i=68</Reference>
        </References>
        <Value>
            <uax:String>http://MyTestOfExtensions</uax:String>
        </Value>
    </UAVariable>
    <UADataType NodeId="ns=1;i=3000" BrowseName="1:MyStructureType">
        <DisplayName>MyStructureType</DisplayName>
        <References>
            <Reference ReferenceType="HasSubtype" IsForward="false">i=22</Reference>
            <Reference ReferenceType="HasEncoding">ns=1;i=5001</Reference>
            <Reference ReferenceType="HasEncoding">ns=1;i=5002</Reference>
        </References>
        <Definition Name="1:MyStructureType">
            <Field DataType="i=17" Name="NodeId"/>
            <Field DataType="i=20" Name="QualifiedName"/>
        </Definition>
    </UADataType>
    <UAObject SymbolicName="DefaultBinary" NodeId="ns=1;i=5001" BrowseName="Default Binary">
        <DisplayName>Default Binary</DisplayName>
        <References>
            <Reference ReferenceType="HasTypeDefinition">i=76</Reference>
        </References>
    </UAObject>
    <UAObject SymbolicName="DefaultXML" NodeId="ns=1;i=5002" BrowseName="Default XML">
        <DisplayName>Default XML</DisplayName>
        <References>
            <Reference ReferenceType="HasTypeDefinition">i=76</Reference>
        </References>
    </UAObject>
    <UAVariable DataType="ns=1;i=3000" NodeId="ns=1;i=6021" BrowseName="1:StructureTest" ParentNodeId="i=2253" UserAccessLevel="3" AccessLevel="3">
        <DisplayName>StructureTest</DisplayName>
        <References>
            <Reference ReferenceType="Organizes" IsForward="false">i=2253</Reference>
            <Reference ReferenceType="HasTypeDefinition">i=63</Reference>
        </References>
        <Value>
            <uax:ExtensionObject>
                <uax:TypeId>
                    <uax:Identifier>ns=1;i=5002</uax:Identifier>
                </uax:TypeId>
                <uax:Body>
                    <MyStructureType xmlns="http://MyTestOfExtensions/Types.xsd">
                        <NodeId>
                            <uax:Identifier>ns=1;i=42</uax:Identifier>
                        </NodeId>
                        <QualifiedName>
                            <uax:NamespaceIndex>1</uax:NamespaceIndex>
                            <uax:Name>zweiundvierzig</uax:Name>
                        </QualifiedName>
                    </MyStructureType>
                </uax:Body>
            </uax:ExtensionObject>
        </Value>
    </UAVariable>
</UANodeSet>

- added protected property XmlNamespace to BaseComplexType
- use XmlNamespace instead of TypeId.NamespaceUri for PushNamespace of
  encoder/decoder
- adapt Encode/Decode method in OptionalFieldsCompexType and
  UnionComplexType

Change was needed if Xml schema in Xml nodeset differ from the custom
OPC UA namespace
Only effects XML encoding and decoding from values of customized structured datatypes.
@mregen mregen self-requested a review April 28, 2021 16:36
@SBaeumler
Copy link
Contributor Author

Hi,

If you have further question, Don’t hesitate to contact me.

Best regards
Sebastian

@mregen mregen self-assigned this Apr 29, 2021
Copy link
Contributor

@mregen mregen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the explanation and the fix!

@mregen mregen merged commit ea1e2b3 into OPCFoundation:master Apr 30, 2021
@SBaeumler SBaeumler changed the title Fixed issue with XML namespace schema while decode an XML nodeset Fixed issue with XML namespace schema while decoding an XML nodeset Apr 30, 2021
@SBaeumler SBaeumler deleted the ComplexTypes branch April 30, 2021 06:37
@mregen
Copy link
Contributor

mregen commented May 3, 2021

Hi @SBaeumler , just out of personal interest maybe you can share how you use the library with Siome as I'm curious how the bug with the complex types occured? Cheers, Martin

@SBaeumler
Copy link
Contributor Author

Hi @mregen, we use SIOME only as source of our nodesets.
We use the ComplexTypes library in another software to read custom nodesets for internal use.

SIOME generate the XML namespace in the same way the UAModeler do it.
But how the XML Namespace locks like, is defined by the developer of the nodeset it self.
It can be equal to the OPC UA namespace, or is can look like the XML Namespace xmlns:uax="http://opcfoundation.org/UA/2008/02/Types.xsd"
That is an extension of the "http://opcfoundation.org/UA" OPC UA Namespace.

Best regards,
Sebastian

@mregen
Copy link
Contributor

mregen commented May 4, 2021

Hi @SBaeumler , thanks for the info. I'm planning to add a mock interface to the complex types lib to be able to create the types from DataTypeDefinition or Dictionary without session. If you have an ask for specific functionality that should be covered by such an approach please let me know, I'm looking for requirements. Cheers, Martin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants