3 # Copyright 2013 Thadeu Lima de Souza Cascardo <cascardo@cascardo.info>
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # -*- mode: python; encoding: utf-8; -*-
18 import xml.dom.minidom
21 def __init__(self, el):
24 def get_attr(self, attr):
25 if attr in self.el.attributes.keys():
26 return self.el.attributes[attr].nodeValue
29 def set_attr(self, attr, val):
30 self.el.setAttribute(attr, val)
33 def __init__(self, element):
34 self.element = element
37 for i in self.element.getElementsByTagName("item"):
38 self.items.append(Item(i))
40 def _get_attr(self, el, attr):
41 if attr in el.attributes.keys():
42 return el.attributes[attr].nodeValue
45 def _set_attr(self, el, attr, val):
46 el.setAttribute(attr, val)
48 def get_attr(self, attr):
49 return self._get_attr(self.element, attr)
51 def set_attr(self, attr, val):
52 self._set_attr(self.element, attr, val)
54 def add_item(self, item):
55 self.items.append(item)
56 self.element.appendChild(item.el)
59 item = Item(self.element.ownerDocument.createElement("item"))
63 def remove_item(self, i):
65 els = self.element.getElementsByTagName("item")
66 self.element.removeChild(els[i])
68 def find(self, attr, value):
70 if i.get_attr(attr) == value:
74 if __name__ == '__main__':
75 doc = xml.dom.minidom.DOMImplementation().createDocument("", "doc", "")
76 el = doc.createElement("items")
79 items.new_item().set_attr("value", "0,00")
80 items.set_attr("total", "0,00")
82 print items.element.toprettyxml()
85 print i.get_attr("value")
87 # vim:tabstop=4:expandtab:smartindent