Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python2..../Demo/xml
File: roundtrip.py
"""
[0] Fix | Delete
A simple demo that reads in an XML document and spits out an equivalent,
[1] Fix | Delete
but not necessarily identical, document.
[2] Fix | Delete
"""
[3] Fix | Delete
[4] Fix | Delete
import sys
[5] Fix | Delete
[6] Fix | Delete
from xml.sax import saxutils, handler, make_parser
[7] Fix | Delete
[8] Fix | Delete
# --- The ContentHandler
[9] Fix | Delete
[10] Fix | Delete
class ContentGenerator(handler.ContentHandler):
[11] Fix | Delete
[12] Fix | Delete
def __init__(self, out=sys.stdout):
[13] Fix | Delete
handler.ContentHandler.__init__(self)
[14] Fix | Delete
self._out = out
[15] Fix | Delete
[16] Fix | Delete
# ContentHandler methods
[17] Fix | Delete
[18] Fix | Delete
def startDocument(self):
[19] Fix | Delete
self._out.write('<?xml version="1.0" encoding="iso-8859-1"?>\n')
[20] Fix | Delete
[21] Fix | Delete
def startElement(self, name, attrs):
[22] Fix | Delete
self._out.write('<' + name)
[23] Fix | Delete
for (name, value) in attrs.items():
[24] Fix | Delete
self._out.write(' %s="%s"' % (name, saxutils.escape(value)))
[25] Fix | Delete
self._out.write('>')
[26] Fix | Delete
[27] Fix | Delete
def endElement(self, name):
[28] Fix | Delete
self._out.write('</%s>' % name)
[29] Fix | Delete
[30] Fix | Delete
def characters(self, content):
[31] Fix | Delete
self._out.write(saxutils.escape(content))
[32] Fix | Delete
[33] Fix | Delete
def ignorableWhitespace(self, content):
[34] Fix | Delete
self._out.write(content)
[35] Fix | Delete
[36] Fix | Delete
def processingInstruction(self, target, data):
[37] Fix | Delete
self._out.write('<?%s %s?>' % (target, data))
[38] Fix | Delete
[39] Fix | Delete
# --- The main program
[40] Fix | Delete
[41] Fix | Delete
if __name__ == '__main__':
[42] Fix | Delete
parser = make_parser()
[43] Fix | Delete
parser.setContentHandler(ContentGenerator())
[44] Fix | Delete
parser.parse(sys.argv[1])
[45] Fix | Delete
[46] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function