Revision 28
Added by Aaron Marcuse-Kubitza about 13 years ago
scripts/xml2db/xml_util.py | ||
---|---|---|
1 | 1 |
# XML DOM tree manipulation |
2 | 2 |
|
3 | 3 |
from xml.dom import Node |
4 |
import xml.dom.minidom |
|
4 | 5 |
|
5 | 6 |
def name_of(node): return node.tagName.lower() |
6 | 7 |
|
... | ... | |
80 | 81 |
children.append(child) |
81 | 82 |
if last_only: break |
82 | 83 |
return children |
84 |
|
|
85 |
_writexml_orig = xml.dom.minidom.Element.writexml |
|
86 |
|
|
87 |
def _writexml(self, writer, indent="", addindent="", newl=""): |
|
88 |
if self.firstChild != None and is_text(self): |
|
89 |
self.normalize() |
|
90 |
writer.write(indent+'<'+self.tagName) |
|
91 |
for attr_idx in range(self.attributes.length): |
|
92 |
attr = self.attributes.item(attr_idx) |
|
93 |
writer.write(' '+attr.name+'='+attr.value) |
|
94 |
writer.write('>'+value(self)+'</'+self.tagName+'>'+newl) |
|
95 |
else: _writexml_orig(self, writer, indent, addindent, newl) |
|
96 |
|
|
97 |
xml.dom.minidom.Element.writexml = _writexml |
scripts/data2xml/xml_util.py | ||
---|---|---|
1 | 1 |
# XML DOM tree manipulation |
2 | 2 |
|
3 | 3 |
from xml.dom import Node |
4 |
import xml.dom.minidom |
|
4 | 5 |
|
5 | 6 |
def name_of(node): return node.tagName.lower() |
6 | 7 |
|
... | ... | |
80 | 81 |
children.append(child) |
81 | 82 |
if last_only: break |
82 | 83 |
return children |
84 |
|
|
85 |
_writexml_orig = xml.dom.minidom.Element.writexml |
|
86 |
|
|
87 |
def _writexml(self, writer, indent="", addindent="", newl=""): |
|
88 |
if self.firstChild != None and is_text(self): |
|
89 |
self.normalize() |
|
90 |
writer.write(indent+'<'+self.tagName) |
|
91 |
for attr_idx in range(self.attributes.length): |
|
92 |
attr = self.attributes.item(attr_idx) |
|
93 |
writer.write(' '+attr.name+'='+attr.value) |
|
94 |
writer.write('>'+value(self)+'</'+self.tagName+'>'+newl) |
|
95 |
else: _writexml_orig(self, writer, indent, addindent, newl) |
|
96 |
|
|
97 |
xml.dom.minidom.Element.writexml = _writexml |
Also available in: Unified diff
Added patch for xml.dom.minidom.Element.writexml to avoid adding extra whitespace around text nodes