3 # This file is part of jack_mixer
5 # Copyright (C) 2006 Nedko Arnaudov <nedko@arnaudov.name>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; version 2 of the License
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 from serialization import *
22 import xml.dom.minidom
24 class xml_serialization(serialization_backend):
26 self.doctype = xml.dom.getDOMImplementation().createDocumentType("pyserialization", None, None)
28 def get_root_serialization_object(self, name):
29 self.doc = xml.dom.getDOMImplementation().createDocument(xml.dom.EMPTY_NAMESPACE, name, self.doctype)
30 return xml_serialization_object(self.doc, self.doc.documentElement)
32 def get_root_unserialization_object(self, name):
33 if name != self.doc.documentElement.nodeName:
35 return xml_serialization_object(self.doc, self.doc.documentElement)
37 def get_child_serialization_object(self, name, backend_object):
38 child = self.doc.createElement(name)
39 backend_object.element.appendChild(child)
40 return xml_serialization_object(self.doc, child)
43 print >>file, self.doc.toprettyxml()
46 self.doc = xml.dom.minidom.parse(file)
48 class xml_serialization_object:
49 def __init__(self, doc, element):
51 self.element = element
53 def add_property(self, name, value):
54 self.add_property_as_attribute(name, value)
56 def add_property_as_attribute(self, name, value):
57 self.element.setAttribute(name, value)
59 #def add_property_as_child_element(self, name, value):
60 # child = self.doc.createElement(name)
61 # value = self.doc.createTextNode(value)
62 # child.appendChild(value)
63 # self.element.appendChild(child)
66 child_elements = self.element.childNodes
68 for child in child_elements:
69 if child.nodeType == child.ELEMENT_NODE:
70 childs.append(xml_serialization_object(self.doc, child))
73 def get_properties(self):
74 properties = self.element.attributes
76 for i in range(properties.length):
77 dictionary[properties.item(i).name] = properties.item(i).nodeValue
80 def serialization_name(self):
81 return self.element.nodeName