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
25 class xml_serialization(serialization_backend
):
27 self
.doctype
= xml
.dom
.implementation
.createDocumentType("pyserialzation", None, None)
29 def get_root_serialization_object(self
, name
):
30 self
.doc
= xml
.dom
.implementation
.createDocument(xml
.dom
.EMPTY_NAMESPACE
, name
, self
.doctype
)
31 return xml_serialization_object(self
.doc
, self
.doc
.documentElement
)
33 def get_root_unserialization_object(self
, name
):
34 if name
!= self
.doc
.documentElement
.nodeName
:
36 return xml_serialization_object(self
.doc
, self
.doc
.documentElement
)
38 def get_child_serialization_object(self
, name
, backend_object
):
39 child
= self
.doc
.createElement(name
)
40 backend_object
.element
.appendChild(child
)
41 return xml_serialization_object(self
.doc
, child
)
44 xml
.dom
.ext
.PrettyPrint(self
.doc
, file)
47 self
.doc
= xml
.dom
.minidom
.parse(file)
49 #xml.dom.ext.PrettyPrint(self.doc)
51 class xml_serialization_object
:
52 def __init__(self
, doc
, element
):
54 self
.element
= element
56 def add_property(self
, name
, value
):
57 self
.add_property_as_attribute(name
, value
)
59 def add_property_as_attribute(self
, name
, value
):
60 self
.element
.setAttribute(name
, value
)
62 #def add_property_as_child_element(self, name, value):
63 # child = self.doc.createElement(name)
64 # value = self.doc.createTextNode(value)
65 # child.appendChild(value)
66 # self.element.appendChild(child)
69 child_elements
= self
.element
.childNodes
71 for child
in child_elements
:
72 if child
.nodeType
== child
.ELEMENT_NODE
:
73 childs
.append(xml_serialization_object(self
.doc
, child
))
76 def get_properties(self
):
77 properties
= self
.element
.attributes
79 for i
in range(properties
.length
):
80 dictionary
[properties
.item(i
).name
] = properties
.item(i
).nodeValue
83 def serialization_name(self
):
84 return self
.element
.nodeName