Revision 1720
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/xml_dom.py | ||
---|---|---|
136 | 136 |
if node.firstChild != None: return node.firstChild.nodeValue |
137 | 137 |
else: return node.nodeValue |
138 | 138 |
|
139 |
def is_whitespace(node): return is_text_node(node) and value(node).isspace() |
|
140 |
|
|
139 | 141 |
def set_value(node, value): |
140 | 142 |
if is_elem(node): node.appendChild(node.ownerDocument.createTextNode(value)) |
141 | 143 |
else: node.nodeValue = value |
... | ... | |
205 | 207 |
|
206 | 208 |
##### minidom modifications |
207 | 209 |
|
210 |
#### Module |
|
211 |
|
|
208 | 212 |
minidom._write_data = lambda writer, data: writer.write(escape(data)) |
209 | 213 |
|
210 | 214 |
minidom.Node.__iter__ = lambda self: NodeIter(self) |
... | ... | |
215 | 219 |
minidom.Node.__repr__ = __Node_str |
216 | 220 |
minidom.Element.__repr__ = __Node_str |
217 | 221 |
|
218 |
def __Attr_str(self): return escape(self.name)+'="'+escape(self.value)+'"' |
|
219 |
minidom.Attr.__str__ = __Attr_str |
|
220 |
minidom.Attr.__repr__ = __Attr_str |
|
222 |
#### Node |
|
221 | 223 |
|
222 | 224 |
minidom.Node.pop = lambda self: self.removeChild(self.lastChild) |
223 | 225 |
|
... | ... | |
225 | 227 |
while not is_empty(self): self.pop() |
226 | 228 |
minidom.Node.clear = __Node_clear |
227 | 229 |
|
230 |
#### Text |
|
231 |
|
|
232 |
__Text_writexml_orig = minidom.Text.writexml |
|
233 |
def __Text_writexml(self, *args, **kw_args): |
|
234 |
if is_whitespace(self): pass # we add our own whitespace |
|
235 |
else: __Text_writexml_orig(self, *args, **kw_args) |
|
236 |
minidom.Text.writexml = __Text_writexml |
|
237 |
|
|
238 |
#### Attr |
|
239 |
|
|
240 |
def __Attr_str(self): return escape(self.name)+'="'+escape(self.value)+'"' |
|
241 |
minidom.Attr.__str__ = __Attr_str |
|
242 |
minidom.Attr.__repr__ = __Attr_str |
|
243 |
|
|
244 |
#### Element |
|
245 |
|
|
228 | 246 |
def __Element_write_opening(self, writer, indent='', addindent='', newl=''): |
229 | 247 |
writer.write(indent+'<'+escape(self.tagName)) |
230 | 248 |
for attr_idx in xrange(self.attributes.length): |
... | ... | |
236 | 254 |
writer.write('</'+escape(self.tagName)+'>'+newl) |
237 | 255 |
minidom.Element.write_closing = __Element_write_closing |
238 | 256 |
|
239 |
_writexml_orig = minidom.Element.writexml |
|
257 |
__Element_writexml_orig = minidom.Element.writexml
|
|
240 | 258 |
def __Element_writexml(self, writer, indent='', addindent='', newl=''): |
241 | 259 |
if isinstance(indent, int): indent = addindent*indent |
242 | 260 |
if is_simple(self): |
243 | 261 |
writer.write(indent) |
244 |
_writexml_orig(self, writer) |
|
262 |
__Element_writexml_orig(self, writer)
|
|
245 | 263 |
writer.write(newl) |
246 |
else: _writexml_orig(self, writer, indent, addindent, newl) |
|
264 |
else: __Element_writexml_orig(self, writer, indent, addindent, newl)
|
|
247 | 265 |
minidom.Element.writexml = __Element_writexml |
248 | 266 |
|
267 |
#### Document |
|
268 |
|
|
249 | 269 |
def __Document_write_opening(self, writer, indent='', addindent='', newl='', |
250 | 270 |
encoding=None): |
251 | 271 |
xmlDecl = '<?xml version="1.0" ' |
Also available in: Unified diff
xml_dom.py: Don't print whitespace from parsed XML document when pretty-printing XML. minidom modifications section: Added subsection labels for the class each modification applies to.