Project

General

Profile

« Previous | Next » 

Revision 299

Import xml.dom.minidom as minidom

View differences:

lib/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()
bin/map
6 6
import os.path
7 7
import sys
8 8
import traceback
9
import xml.dom.minidom
9
import xml.dom.minidom as minidom
10 10

  
11 11
sys.path.append(os.path.dirname(__file__)+"/../lib")
12 12

  
......
72 72
        stream.close()
73 73
    in_is_xml = in_is_xpaths and not in_is_db
74 74
    
75
    if in_is_xml: doc0 = xml.dom.minidom.parse(sys.stdin)
75
    if in_is_xml: doc0 = minidom.parse(sys.stdin)
76 76
    
77 77
    def process_xml(use_row):
78 78
        '''Maps datasource to XML tree'''
......
163 163
        finally:
164 164
            out_db.rollback()
165 165
            out_db.close()
166
    else:
166
    else: # output is XML
167 167
        def use_row(root): pass # TODO: implement this
168
        xml_dom.writexml(sys.stdout, get_xml(use_row)) # output is XML
168
        output = sys.stdout
169
        doc1 = get_xml(use_row)
170
        xml_dom.writexml(output, doc1)
169 171

  
170 172
try: main()
171 173
except Parser.SyntaxException, e: raise SystemExit(str(e))

Also available in: Unified diff