2005年04月25日 星期一 10:07
在学习limodou的使用minidom来处理xml实例的时候,读取catalog.xml出现以下错误: >>> import xml.dom.minidom >>> dom = xml.dom.minidom.parse('d:\catalog.xml') Traceback (innermost last): File "", line 1, in ? dom = xml.dom.minidom.parse('d:\catalog.xml') File "D:\Python20\lib\xml\dom\minidom.py", line 471, in parse return _doparse(pulldom.parse, args, kwargs) File "D:\Python20\lib\xml\dom\minidom.py", line 464, in _doparse events = apply(func, args, kwargs) File "D:\Python20\lib\xml\dom\pulldom.py", line 225, in parse parser = xml.sax.make_parser() File "D:\Python20\lib\xml\sax\__init__.py", line 76, in make_parser return _create_parser(parser_name) File "D:\Python20\lib\xml\sax\__init__.py", line 100, in _create_parser drv_module = __import__(parser_name,{},{},['create_parser']) File "D:\Python20\lib\xml\sax\expatreader.py", line 13, in ? from xml.sax import xmlreader, saxutils, handler File "D:\Python20\lib\xml\sax\saxutils.py", line 10, in ? _StringTypes = [types.StringType, types.UnicodeType] AttributeError: UnicodeType 环境是python2.0、windows 2000 pro english 用b=a.encode('utf-8')读取文件内容重新写入,故障依旧。 请问如何解决,请指教,谢谢! -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20050425/c738594d/attachment.htm
2005年04月25日 星期一 10:11
丢弃 minidom 吧! ElementTree 现在非常非常的好用了! 在05-4-25,makeyoubad163<makeyoubad163 at 163.com> 写道: > 在学习limodou的使用minidom来处理xml实例的时候,读取catalog.xml出现以下错误: > > >>> import xml.dom.minidom > >>> dom = xml.dom.minidom.parse('d:\catalog.xml') > Traceback (innermost last): > File "", line 1, in ? > dom = xml.dom.minidom.parse('d:\catalog.xml') > File "D:\Python20\lib\xml\dom\minidom.py", line 471, in > parse > return _doparse(pulldom.parse, args, kwargs) > File "D:\Python20\lib\xml\dom\minidom.py", line 464, in > _doparse > events = apply(func, args, kwargs) > File "D:\Python20\lib\xml\dom\pulldom.py", line 225, in > parse > parser = xml.sax.make_parser() > File "D:\Python20\lib\xml\sax\__init__.py", line 76, in > make_parser > return _create_parser(parser_name) > File "D:\Python20\lib\xml\sax\__init__.py", line 100, in > _create_parser > drv_module = > __import__(parser_name,{},{},['create_parser']) > File "D:\Python20\lib\xml\sax\expatreader.py", line 13, in > ? > from xml.sax import xmlreader, saxutils, handler > File "D:\Python20\lib\xml\sax\saxutils.py", line 10, in ? > _StringTypes = [types.StringType, types.UnicodeType] > AttributeError: UnicodeType > > 环境是python2.0、windows 2000 pro english > 用b=a.encode('utf-8')读取文件内容重新写入,故障依旧。 > 请问如何解决,请指教,谢谢! > > > > > > > > > 什么邮箱配有网络书签功能?好网址随时记录。 > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese > > > -- [Time is unimportant, only life important!]
2005年04月25日 星期一 10:19
你的整个文件需要使用utf-8文件编码保存才可以。而不是把文件读出来进行utf-8编码转换。 xml的解析器会根据xml的头encoding="xxx"来自动进行编码转换的。它会自动把某种编码转为unicode的。因此,如果你想使用utf-8,那么首先要把你的xml文件保存为utf-8编码才可以。 在05-4-25,makeyoubad163<makeyoubad163 at 163.com> 写道: > 在学习limodou的使用minidom来处理xml实例的时候,读取catalog.xml出现以下错误: > > >>> import xml.dom.minidom > >>> dom = xml.dom.minidom.parse('d:\catalog.xml') > Traceback (innermost last): > File "", line 1, in ? > dom = xml.dom.minidom.parse('d:\catalog.xml') > File "D:\Python20\lib\xml\dom\minidom.py", line 471, in > parse > return _doparse(pulldom.parse, args, kwargs) > File "D:\Python20\lib\xml\dom\minidom.py", line 464, in > _doparse > events = apply(func, args, kwargs) > File "D:\Python20\lib\xml\dom\pulldom.py", line 225, in > parse > parser = xml.sax.make_parser() > File "D:\Python20\lib\xml\sax\__init__.py", line 76, in > make_parser > return _create_parser(parser_name) > File "D:\Python20\lib\xml\sax\__init__.py", line 100, in > _create_parser > drv_module = > __import__(parser_name,{},{},['create_parser']) > File "D:\Python20\lib\xml\sax\expatreader.py", line 13, in > ? > from xml.sax import xmlreader, saxutils, handler > File "D:\Python20\lib\xml\sax\saxutils.py", line 10, in ? > _StringTypes = [types.StringType, types.UnicodeType] > AttributeError: UnicodeType > > 环境是python2.0、windows 2000 pro english > 用b=a.encode('utf-8')读取文件内容重新写入,故障依旧。 > 请问如何解决,请指教,谢谢! > > > > > > > > > 什么邮箱配有网络书签功能?好网址随时记录。 > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese > > > -- I like python! My Donews Blog: http://www.donews.net/limodou New Google Maillist: http://groups-beta.google.com/group/python-cn
Zeuux © 2025
京ICP备05028076号