Python中的XML解析

编程入门 行业动态 更新时间:2024-10-07 20:32:15
本文介绍了Python中的XML解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想使用python解析一个简单的小型XML文件,但是在pyXML上的工作似乎已经停止了.如果可能的话,我想使用python 2.6.谁能推荐可以与2.6兼容的XML解析器?

I'd like to parse a simple, small XML file using python however work on pyXML seems to have ceased. I'd like to use python 2.6 if possible. Can anyone recommend an XML parser that will work with 2.6?

谢谢

推荐答案

如果它又小又简单,则只需使用标准库:

If it's small and simple then just use the standard library:

from xml.dom.minidom import parse doc = parse("filename.xml")

这将返回实现标准文档对象模型API

如果以后需要执行诸如模式验证或XPath查询之类的复杂操作,那么我建议第三方 lxml模块,它是流行的libxml2 C库的包装.

If you later need to do complex things like schema validation or XPath querying then I recommend the third-party lxml module, which is a wrapper around the popular libxml2 C library.

更多推荐

Python中的XML解析

本文发布于:2023-11-28 06:13:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1641249.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Python   XML

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!