开发者

Python: which XML parsing library will work out-of-the-box for Python 2.4 and up?

开发者 https://www.devze.com 2022-12-14 14:52 出处:网络
How can I make sure that my Python script, which will be doing some XML parsing, will Just Work with Python 2.4, 2.5 and 2.6?

How can I make sure that my Python script, which will be doing some XML parsing, will Just Work with Python 2.4, 2.5 and 2.6?

Specifically, which (if any) XML parsing library is present in, and compatible between, all those versions?

Edit: the working-out-of-the-box requirement is in place because the XML parsing I'm going to need to do is very limited (just grabbing some values) and I'm going to need to run this scr开发者_StackOverflow社区ipt on a bunch of different platforms, so I'd rather deal with a crappy XML API then try to get lxml installed on Mac, Linux and Windows.


minidom is available in Python 2.0 and later.

However, if I were you, I would strongly consider using ElementTree which is available in Python 2.5 and later. Its syntax is much more pleasant.

2.4 users can reasonably easily download ElementTree, 2.5+ it will work without any additional dependencies. But I may be spoiled by rarely needing to target pre-2.5, myself.


So, basically intersect the result of "xml" in these pages:

  • https://docs.python.org/release/2.4/modindex.html
  • https://docs.python.org/release/2.5/modindex.html
  • https://docs.python.org/release/2.6/modindex.html

That leaves xml.dom and xml.sax.

If you could relieve the "out-of-the-box"-requirement: lxml


You can use minidom

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号