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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.