easy, easy, XML

I keep answering XML questions on Python's XML-SIG mailing list and on comp.lang.python. Most of them go: "Here's my SAX/minidom/PyXML code. I can't find the bug. Can you help me?"

Yes, I can. My default answers are:

  • Don't use SAX. It's well designed to hide the bugs in your code, but it's no good for doing XML work.
  • Don't use PyXML. It hasn't been maintained for years, so if you have problems with it, you're lucky if there is someone still alive who can help you out.
  • Avoid minidom and other DOM implementations. DOM is good if you need to write code the Java way. It's no good if you want to get XML work done.

The second paragraph of my answer then goes:

Use ElementTree or lxml instead. The first is part of the standard library since Python 2.5, and the latter is available from http://lxml.de/. Both are mostly compatible, both are well maintained, both provide mature and stable libraries that are easy to use. Read the tutorial and get started.

It's an advantage for Python to have these tools available, and I'm still missing a straight link from the Python homepage to both of them. These are the tools that newbees should run straight into when they look for XML support in Python, not the outdated pages that are currently hidden behind the "XML" link.