Skip to content

Commit fbc2e5a

Browse files
Andreas Monschoroulet
authored andcommitted
Various fixes in the xmlexporter
- Map alias namespaces from server space to xml space before exporting in order to avoid `BadNodeIdUnknown` exceptions when importing the resulting XML file. - Only use `ObjectIdNames` for name lookups if the target nodeid is in namespace 0. - Use the name part of the browse name when creating mappings for nodeids not in namespace 0. Otherwise we end up with aliases like e.g. `<Alias Alias="ns=2;i=4002">ns=2;i=4002</Alias>`.
1 parent 954e3d7 commit fbc2e5a

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

opcua/common/xmlexporter.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ def _add_alias_els(self):
330330
for nodeid in ordered_keys:
331331
name = self.aliases[nodeid]
332332
ref_el = Et.SubElement(aliases_el, 'Alias', Alias=name)
333-
ref_el.text = nodeid.to_string()
333+
ref_el.text = self._node_to_string(nodeid)
334334

335335
# insert behind the namespace element
336336
self.etree.getroot().insert(1, aliases_el)
@@ -340,10 +340,11 @@ def _add_ref_els(self, parent_el, obj):
340340
refs_el = Et.SubElement(parent_el, 'References')
341341

342342
for ref in refs:
343-
if ref.ReferenceTypeId.Identifier in o_ids.ObjectIdNames:
343+
if ref.ReferenceTypeId.NamespaceIndex == 0 and ref.ReferenceTypeId.Identifier in o_ids.ObjectIdNames:
344344
ref_name = o_ids.ObjectIdNames[ref.ReferenceTypeId.Identifier]
345345
else:
346-
ref_name = ref.ReferenceTypeId.to_string()
346+
ref_name = self.server.get_node(ref.ReferenceTypeId).get_browse_name().Name
347+
347348
ref_el = Et.SubElement(refs_el, 'Reference')
348349
ref_el.attrib['ReferenceType'] = ref_name
349350
if not ref.IsForward:

0 commit comments

Comments
 (0)