xml.etree 还是 xml.dom? [英] xml.etree or xml.dom?

查看:44
本文介绍了xml.etree 还是 xml.dom?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试读取一些 xml,但我不确定应该使用哪个库.

I am trying to read some xml, but I'm not sure which library I should use.

xml.etree 和 xml.dom 哪个更好,为什么?

What is better xml.etree or xml.dom, and why?

请解释你的答案并提出论据.

Please, explain your answers and give arguments.

此外,您认为其中一个会被弃用吗?哪一个?

Also, do you think one of them is going to get deprecated? Which one?

推荐答案

两者都不会被弃用.

ElementTree (xml.etree) 是一个用于访问 XML 的 Pythonic API.DOM (xml.dom) 是一种跨平台、独立于语言的标准.

ElementTree (xml.etree) is a pythonic API to access XML. DOM (xml.dom) is a cross-platform, language independent standard.

除非您有令人信服的理由改用 XML DOM,否则请使用 ElementTree.对于 python 代码,ElementTree API 比 DOM API 更容易使用.

Use ElementTree unless you have a compelling reason to use the XML DOM instead. For python code, the ElementTree API is far easier to use than the DOM API.

如果你不反对安装额外的 python 库,你应该看看 lxml 也是;它还在非常快速的 C 库之上实现了 ElementTree API,并添加了更多选项以有效处理 XML.

If you are not averse to installing extra python libraries, you should take a look at the lxml library as well; it implements the ElementTree API as well, on top of very fast C libraries, and adds a few more options to work with XML effectively.

这篇关于xml.etree 还是 xml.dom?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆