Python论坛  - 讨论区

标题:[python-chinese] 请教minidom处理xml的问题

2005年04月25日 星期一 10:07

makeyoubad163 makeyoubad163 at 163.com
Mon Apr 25 10:07:01 HKT 2005

在学习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

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2005年04月25日 星期一 10:11

Zoom Quiet zoom.quiet at gmail.com
Mon Apr 25 10:11:31 HKT 2005

丢弃 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!]

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2005年04月25日 星期一 10:19

limodou limodou at gmail.com
Mon Apr 25 10:19:01 HKT 2005

你的整个文件需要使用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

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号