1 |
xabbu |
1.1 |
#fraggleParserXML: Class for parsing XML from a stream or file |
2 |
|
|
|
3 |
|
|
import sys |
4 |
xabbu |
1.3 |
import fraggleError |
5 |
|
|
|
6 |
xabbu |
1.5 |
#from fraggleError import * |
7 |
xabbu |
1.1 |
from xml.dom.ext.reader import Sax2 |
8 |
xabbu |
1.2 |
from xml.marshal import * |
9 |
xabbu |
1.1 |
|
10 |
|
|
def create(parent): |
11 |
xabbu |
1.2 |
return fraggleParserXML(parent) |
12 |
xabbu |
1.1 |
|
13 |
|
|
class fraggleParserXML: |
14 |
xabbu |
1.2 |
def __init_reader__(self): |
15 |
|
|
self.reader = Sax2.Reader() |
16 |
|
|
|
17 |
xabbu |
1.1 |
|
18 |
|
|
def __init__(self,parent): |
19 |
|
|
self.__init_reader__() |
20 |
|
|
|
21 |
|
|
|
22 |
|
|
|
23 |
xabbu |
1.2 |
def parseXML(self,input): |
24 |
xabbu |
1.3 |
try: |
25 |
|
|
dom = self.reader.fromStream(input) |
26 |
|
|
except: |
27 |
xabbu |
1.4 |
fraggleError.errorXMLStreamNotValid() |
28 |
xabbu |
1.1 |
return dom |
29 |
|
|
|
30 |
xabbu |
1.2 |
def printXML(self,inputDom,outputLocation): |
31 |
xabbu |
1.3 |
try: |
32 |
|
|
file = open(outputLocation,"w") |
33 |
|
|
self.reader.PrettyPrint(inputDom,file) |
34 |
|
|
except: |
35 |
xabbu |
1.4 |
fraggleError.errorFileNotFound(outputLocation) |
36 |
xabbu |
1.3 |
|
37 |
|
|
def marshalXML(self,values,outputLocation): |
38 |
|
|
try: |
39 |
|
|
file = open(outputLocation,"w") |
40 |
|
|
# self.marshall.dump(values,file) |
41 |
|
|
generic.dump(values,file) |
42 |
|
|
except: |
43 |
xabbu |
1.4 |
fraggleError.errorFileNotFound(outputLocation) |
44 |
xabbu |
1.1 |
|
45 |
xabbu |
1.3 |
|
46 |
|
|
#print generic.dumps(values) |
47 |
|
|
|
48 |
|
|
def unmarshalXML(self,inputLocation): |
49 |
|
|
try: |
50 |
|
|
file = open(inputLocation,"r") |
51 |
|
|
except: |
52 |
xabbu |
1.5 |
return |
53 |
|
|
#fraggleError.errorFileNotFound(inputLocation) |
54 |
xabbu |
1.3 |
return generic.load(file) |
55 |
|
|
|