Changeset 1438


Ignore:
Timestamp:
22/08/06 12:46:52 (13 years ago)
Author:
domlowe
Message:

Fix for XML unicode problems (I think). Tests files to see what format they are then passes the correct encoding information to elementtree. Requres further testing

Location:
TI02-CSML/trunk/parser
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • TI02-CSML/trunk/parser/API/ops_Dataset.py

    r1170 r1438  
    11''' ops_Dataset  contains operations for root Dataset class''' 
    22from API import * 
     3import codecs 
    34 
    45def testmethod(self): 
     
    78 
    89def parse(self,csmlfile): 
    9         """must be provided with csmlfile 
    10         parses the csmlfile into self """ 
    11         tree = ElementTree(file=csmlfile) 
    12         self.fromXML(tree.getroot()) 
    13         self =parser_extra.ParserPostProcessor(self).resolveReferences() 
    14  
     10    """must be provided with csmlfile   parses the csmlfile into self """ 
     11    #determine encoding 
     12    f = open(csmlfile) 
     13    startoffile=f.readline() 
     14    encoding=xmlEncoding.autoDetectXMLEncoding(startoffile) 
     15    f.close() 
     16    #parse with correct encoding 
     17    tree = parser_extra.encodingParser(csmlfile,encoding) 
     18    self.fromXML(tree.getroot()) 
     19    self =parser_extra.ParserPostProcessor(self).resolveReferences() 
     20     
    1521def getSecurity(self): 
    1622    """ returns a dictonary containing attributeAuthority: role""" 
     
    1925        if hasattr(self.accessControlPolicy,'dgSecurityConditions'): 
    2026            for condition in self.accessControlPolicy.dgSecurityConditions: 
    21                 print dir(condition) 
    2227                #need to test for these but ok for alpha. 
    2328                cond=[] 
  • TI02-CSML/trunk/parser/apicalls.py

    r1344 r1438  
    44import API 
    55 
    6 f='coapec.xml' 
    76f='../Scanner/test.xml' 
    87 
     
    109csml = API.Parser.Dataset() 
    1110csml.parse(f) 
     11 
    1212 
    1313#get list of features in the dataset 
     
    5353subsetCSML, subsetNetCDF, arraySize=feature.subsetToGridSeries(timeSelection,  csmlpath='myfile.xml', ncpath='myfile.nc',**spatialSubsetDictionary) 
    5454 
    55 print subsetCSML #csml document (string) 
     55#parse and pretty print the result 
     56# strCSML=parser_extra.PrettyPrint(subsetCSML) 
     57# strCSML=parser_extra.removeInlineNS(strCSML) 
     58# print strCSML #csml document (string) 
     59print subsetCSML 
    5660print subsetNetCDF # netcdf file (file) 
    5761print 'arraySize: %s' %arraySize 
  • TI02-CSML/trunk/parser/parser_extra.py

    r1350 r1438  
    1010import elementtree.ElementTree as etree 
    1111import string 
     12import cElementTree as ET 
     13import codecs 
     14 
    1215 
    1316#some xml/string manipulation functions. may as well go in this file for now: 
     17 
     18def encodingParser(file, encoding): 
     19    f = codecs.open(file, "r", encoding) 
     20    p = ET.XMLParser(encoding="utf-8") 
     21    while 1: 
     22        s = f.read(65536) 
     23        if not s: 
     24            break 
     25        p.feed(s.encode("utf-8")) 
     26    return ET.ElementTree(p.close()) 
    1427 
    1528 
Note: See TracChangeset for help on using the changeset viewer.