source: trunk/daemon/togad.py @ 4

Last change on this file since 4 was 4, checked in by bastiaans, 18 years ago

daemon/xmlparse.py,
daemon/togad.py:

xmlparse.py -> togad.py

File size: 1.0 KB
Line 
1#!/usr/bin/env python
2
3import xml.sax
4
5class ContentGenerator( xml.sax.handler.ContentHandler ):
6
7    def __init__(self, out = sys.stdout):
8        handler.ContentHandler.__init__(self)
9        self._out = out
10
11    # ContentHandler methods
12       
13    def startDocument(self):
14        self._out.write('<?xml version="1.0" encoding="iso-8859-1"?>\n')
15
16    def startElement(self, name, attrs):
17        self._out.write('<' + name)
18        for (name, value) in attrs.items():
19            self._out.write(' %s="%s"' % (name, saxutils.escape(value)))
20        self._out.write('>')
21
22    def endElement(self, name):
23        self._out.write('</%s>' % name)
24
25    def characters(self, content):
26        self._out.write(saxutils.escape(content))
27
28    def ignorableWhitespace(self, content):
29        self._out.write(content)
30       
31    def processingInstruction(self, target, data):
32        self._out.write('<?%s %s?>' % (target, data))
33
34# --- The main program
35
36parser = xml.sax.make_parser()
37parser.setContentHandler(ContentGenerator())
38parser.parse(sys.argv[1])
Note: See TracBrowser for help on using the repository browser.