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