<?xml version="1.0" encoding="GB2312"?>

<?xml version="1.0" encoding="GB2312"?>

<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0"?>
用以下代码都能读取
from xml.dom import minidom
>>> xmldoc = minidom.parse('c:\\aa.XML')
而 <?xml version="1.0" encoding="GB2312"?>
用以上代码就不能读取,怎样解决读取GB2312呀,请指点一下

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    xmldoc = minidom.parse('c:\\aa.XML')
  File "C:\Python25\lib\xml\dom\minidom.py", line 1913, in parse
    return expatbuilder.parse(file)
  File "C:\Python25\lib\xml\dom\expatbuilder.py", line 924, in parse
    result = builder.parseFile(fp)
  File "C:\Python25\lib\xml\dom\expatbuilder.py", line 207, in parseFile
    parser.Parse(buffer, 0)
ExpatError: unknown encoding: line 1, column 30
>>>
把第一行读出来后,不要使用minidom来读,就是简单的file读取,然后得到它的encoding,再把后面的文本根据encoding,先转为unicode,再转为utf-8,然后再处理就行了。