Project

General

Profile

« Previous | Next » 

Revision 299

Import xml.dom.minidom as minidom

View differences:

xml_dom.py
3 3
import cgi
4 4
from HTMLParser import HTMLParser
5 5
from xml.dom import Node
6
import xml.dom.minidom
6
import xml.dom.minidom as minidom
7 7

  
8 8
import strings
9 9

  
......
123 123
    return children
124 124

  
125 125
def create_doc(root='_'):
126
    return xml.dom.minidom.getDOMImplementation().createDocument(None, root,
126
    return minidom.getDOMImplementation().createDocument(None, root,
127 127
        None)
128 128

  
129 129
def writexml(writer, node): node.writexml(writer, addindent='    ', newl='\n')
130 130

  
131
# xml.dom.minidom modifications
131
# minidom modifications
132 132

  
133
xml.dom.minidom._write_data = lambda writer, data: writer.write(escape(data))
133
minidom._write_data = lambda writer, data: writer.write(escape(data))
134 134

  
135 135
def __write_opening(self, writer, indent='', addindent='', newl=''):
136 136
    writer.write(indent+'<'+self.tagName)
......
138 138
        attr = self.attributes.item(attr_idx)
139 139
        writer.write(' '+attr.name+'='+escape(attr.value))
140 140
    writer.write('>'+newl)
141
xml.dom.minidom.Element.write_opening = __write_opening
141
minidom.Element.write_opening = __write_opening
142 142

  
143 143
def __write_closing(self, writer, indent='', addindent='', newl=''):
144 144
    writer.write('</'+self.tagName+'>'+newl)
145
xml.dom.minidom.Element.write_closing = __write_closing
145
minidom.Element.write_closing = __write_closing
146 146

  
147
_writexml_orig = xml.dom.minidom.Element.writexml
147
_writexml_orig = minidom.Element.writexml
148 148
def __writexml(self, writer, indent='', addindent='', newl=''):
149 149
    if is_text(self):
150 150
        self.write_opening(writer, indent, addindent, '') # no newline
151 151
        writer.write(escape(value(self)))
152 152
        self.write_closing(writer, indent, addindent, newl)
153 153
    else: _writexml_orig(self, writer, indent, addindent, newl)
154
xml.dom.minidom.Element.writexml = __writexml
154
minidom.Element.writexml = __writexml
155 155

  
156
xml.dom.minidom.Node.__str__ = lambda self: self.toxml()
156
minidom.Node.__str__ = lambda self: self.toxml()

Also available in: Unified diff