-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode.py
More file actions
53 lines (39 loc) · 1.29 KB
/
node.py
File metadata and controls
53 lines (39 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
class XMLNode:
def __init__(self, **kwargs):
self._dict_tag_info = kwargs
@property
def tag_name(self):
return self._dict_tag_info['name']
@property
def tag_attr(self):
return self._dict_tag_info['attr']
@property
def tag_text(self):
return self._dict_tag_info['text']
@tag_text.setter
def tag_text(self, text):
self._dict_tag_info['text'] = text
def get_node_info(self):
"""
This method must be implemented by subclasses.
:return: node info as a dictionary of name, attributes and text.
"""
raise NotImplementedError()
class XMLCompositeNode(XMLNode):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self._xml_node_list = []
def get_subnode_list(self):
return self._xml_node_list
def add_node(self, xml_node):
self._xml_node_list.append(xml_node)
def rem_node(self, xml_node):
self._xml_node_list.remove(xml_node)
def get_node_info(self):
info_list = [self._dict_tag_info]
if self._xml_node_list:
info_list.append([node.get_node_info() for node in self._xml_node_list])
return info_list
class XMLLeafNode(XMLNode):
def get_node_info(self):
return self._dict_tag_info