intro.txt 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. Why lxml?
  2. =========
  3. .. contents::
  4. ..
  5. 1 Motto
  6. 2 Aims
  7. Motto
  8. -----
  9. "the thrills without the strangeness"
  10. To explain the motto:
  11. "Programming with libxml2 is like the thrilling embrace of an exotic stranger.
  12. It seems to have the potential to fulfill your wildest dreams, but there's a
  13. nagging voice somewhere in your head warning you that you're about to get
  14. screwed in the worst way." (`a quote by Mark Pilgrim`_)
  15. Mark Pilgrim was describing in particular the experience a Python programmer
  16. has when dealing with libxml2. The default Python bindings of libxml2 are
  17. fast, thrilling, powerful, and your code might fail in some horrible way that
  18. you really shouldn't have to worry about when writing Python code. lxml
  19. combines the power of libxml2 with the ease of use of Python.
  20. .. _`a quote by Mark Pilgrim`: http://diveintomark.org/archives/2004/02/18/libxml2
  21. Aims
  22. ----
  23. The C libraries libxml2_ and libxslt_ have huge benefits:
  24. * Standards-compliant XML support.
  25. * Support for (broken) HTML.
  26. * Full-featured.
  27. * Actively maintained by XML experts.
  28. * fast. fast! FAST!
  29. .. _libxml2: http://www.xmlsoft.org
  30. .. _libxslt: http://xmlsoft.org/XSLT
  31. These libraries already ship with Python bindings, but these Python bindings
  32. mimic the C-level interface. This yields a number of problems:
  33. * very low level and C-ish (not Pythonic).
  34. * underdocumented and huge, you get lost in them.
  35. * UTF-8 in API, instead of Python unicode strings.
  36. * Can easily cause segfaults from Python.
  37. * Require manual memory management!
  38. lxml is a new Python binding for libxml2 and libxslt, completely independent
  39. from these existing Python bindings. Its aims:
  40. * Pythonic API.
  41. * Documented.
  42. * Use Python unicode strings in API.
  43. * Safe (no segfaults).
  44. * No manual memory management!
  45. lxml aims to provide a Pythonic API by following as much as possible the
  46. `ElementTree API`_. We're trying to avoid inventing too many new APIs, or you
  47. having to learn new things -- XML is complicated enough.
  48. .. _`ElementTree API`: http://effbot.org/zone/element-index.htm