1 |
xabbu |
1.1 |
#fraggleParserXML: Class for parsing XML from a stream or file |
2 |
|
|
|
3 |
|
|
import sys |
4 |
|
|
from xml.dom.ext.reader import Sax2 |
5 |
|
|
from xml.marshal import generic |
6 |
|
|
|
7 |
|
|
def create(parent): |
8 |
|
|
return fraggleParserXML() |
9 |
|
|
|
10 |
|
|
class fraggleParserXML: |
11 |
|
|
def __init_reader__(): |
12 |
|
|
reader = Sax2.Reader() |
13 |
|
|
marshall = generic.Marshaller() |
14 |
|
|
|
15 |
|
|
def __init__(self,parent): |
16 |
|
|
self.__init_reader__() |
17 |
|
|
|
18 |
|
|
|
19 |
|
|
|
20 |
|
|
def parseXML(input): |
21 |
|
|
dom = self.reader.fromStream(input) |
22 |
|
|
return dom |
23 |
|
|
|
24 |
|
|
def printXML(inputDom,outputLocation): |
25 |
|
|
file = open(outputLocation,"w") |
26 |
|
|
self.reader.PrettyPrint(inputDom,file) |
27 |
|
|
|
28 |
|
|
def marshalXML(value,outputLocation): |
29 |
|
|
file = open(outputLocation,"w") |
30 |
|
|
marshall.dump(value,file) |
31 |
|
|
|
32 |
|
|
|