self.xmlroot.append(n)
return n
- def append_node(self, node_name, text):
+ def append_node_text(self, node_name, text):
'''Append a new text to the node that has node_name as name
:param node_name str: The name of the node on which append text
# append the text
field.text += text
+ def append_node_attrib(self, node_name, attrib):
+ '''Append a new attributes to the node that has node_name as name
+
+ :param node_name str: The name of the node on which append text
+ :param attrib dixt: The attrib to append
+ '''
+ self.xmlroot.find(node_name).attrib.update(attrib)
+
class readXmlFile(object):
'''Class to manage reading of an xml log file
'''
etree_inst = etree.parse(filePath)
self.xmlroot = etree_inst.parse(filePath)
- def get_attrib_text(self, attribname):
- '''Parse the root nodes and get all node that have the attribname. Return the list of [(value of attribname, text), ...]
+ def get_attrib(self, node_name):
+ '''Get the attibutes of the node node_name in self.xmlroot
+
+ :param node_name str: the name of the node
'''
- lres = []
- # Loop on all root nodes
- for field in self.xmlroot:
- if attribname in field.attrib:
- lres.append((field.attrib[attribname], field.text))
- return lres
+ return self.xmlroot.find(node_name).attrib
def get_node_text(self, node):
'''Get the text of the first node that has name that corresponds to the parameter node