MCPcopy Create free account
hub / github.com/FreeOpcUa/python-opcua / XmlExporter

Class XmlExporter

opcua/common/xmlexporter.py:18–455  ·  view source on GitHub ↗

If it is required that for _extobj_to_etree members to the value should be written in a certain order it can be added to the dictionary below.

Source from the content-addressed store, hash-verified

16
17
18class XmlExporter(object):
19
20 ''' If it is required that for _extobj_to_etree members to the value should be written in a certain
21 order it can be added to the dictionary below.
22 '''
23 extobj_ordered_elements = {
24 ua.NodeId(ua.ObjectIds.Argument) : ['Name',
25 'DataType',
26 'ValueRank',
27 'ArrayDimensions',
28 'Description']
29 }
30
31 def __init__(self, server):
32 self.logger = logging.getLogger(__name__)
33 self.server = server
34 self.aliases = {}
35 self._addr_idx_to_xml_idx = {}
36
37 node_set_attributes = OrderedDict()
38 node_set_attributes['xmlns:xsi'] = 'http://www.w3.org/2001/XMLSchema-instance'
39 node_set_attributes['xmlns:uax'] = 'http://opcfoundation.org/UA/2008/02/Types.xsd'
40 node_set_attributes['xmlns:xsd'] = 'http://www.w3.org/2001/XMLSchema'
41 node_set_attributes['xmlns'] = 'http://opcfoundation.org/UA/2011/03/UANodeSet.xsd'
42
43 self.etree = Et.ElementTree(Et.Element('UANodeSet', node_set_attributes))
44
45 def build_etree(self, node_list, uris=None):
46 """
47 Create an XML etree object from a list of nodes; custom namespace uris are optional
48 Namespaces used by nodes are always exported for consistency.
49 Args:
50 node_list: list of Node objects for export
51 uris: list of namespace uri strings
52
53 Returns:
54 """
55 self.logger.info('Building XML etree')
56
57 self._add_namespaces(node_list, uris)
58
59 # add all nodes in the list to the XML etree
60 for node in node_list:
61 self.node_to_etree(node)
62
63 # add aliases to the XML etree
64 self._add_alias_els()
65
66 def _add_namespaces(self, nodes, uris):
67 idxs = self._get_ns_idxs_of_nodes(nodes)
68
69 ns_array = self.server.get_namespace_array()
70
71 # now add index of provided uris if necessary
72 if uris:
73 self._add_idxs_from_uris(idxs, uris, ns_array)
74
75 # now create a dict of idx_in_address_space to idx_in_exported_file

Callers 3

export_xmlMethod · 0.90
export_xmlMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected