+# Parameter value class
+class xxxParam:
+ # Standard use: for text nodes
+ def __init__(self, node):
+ self.node = node
+ if not node.hasChildNodes():
+ # If does not have child nodes, create empty text node
+ text = tree.dom.createTextNode('')
+ node.appendChild(text)
+ else:
+ text = node.childNodes[0] # first child must be text node
+ assert text.nodeType == minidom.Node.TEXT_NODE
+ self.textNode = text
+ # Value returns string
+ def value(self):
+ return str(self.textNode.data)
+ def update(self, value):
+ self.textNode.data = value
+ def remove(self):
+ self.node.parentNode.removeChild(self.node)
+ self.node.unlink()
+
+# Content parameter
+class xxxParamContent:
+ def __init__(self, node):
+ self.node = node
+ data, l = [], [] # data is needed to quicker value retrieval
+ nodes = node.childNodes[:] # make a copy of the child list
+ for n in nodes:
+ if n.nodeType == minidom.Node.ELEMENT_NODE:
+ assert n.tagName == 'item', 'bad content content'
+ if not n.hasChildNodes():
+ # If does not have child nodes, create empty text node
+ text = tree.dom.createTextNode('')
+ node.appendChild(text)
+ else:
+ # !!! normalize?
+ text = n.childNodes[0] # first child must be text node
+ assert text.nodeType == minidom.Node.TEXT_NODE
+ l.append(text)
+ data.append(text.data)
+ else: # remove other
+ node.removeChild(n)
+ n.unlink()
+ self.l, self.data = l, data
+ def value(self):
+ return self.data
+ def update(self, value):
+ # If number if items is not the same, recreate children
+ if len(value) != len(self.l): # remove first if number of items has changed
+ for n in self.node.childNodes:
+ self.node.removeChild(n)
+ l = []
+ for str in value:
+ itemElem = tree.dom.createElement('item')
+ itemText = tree.dom.createTextNode(str)
+ itemElem.appendChild(itemText)
+ self.node.appendChild(itemElem)
+ l.append(itemText)
+ else:
+ for i in range(len(value)):
+ self.l[i].data = value[i]
+ self.data = value
+
+################################################################################
+