Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 40 lines (30 sloc) 1.501 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
lxml.etree versus ElementTree
=============================

A lot of care has been taken to ensure compatibility between etree and
ElementTree. Nonetheless, besides missing features in lxml.etree, some
differences and incompatibilities exist:

* Importing etree is obviously different; etree uses a lower case
  package name, while ElementTree a combination of upper-case and
  lower case in imports::

    # etree
    from lxml.etree import Element

    # ElementTree
    from elementtree.ElementTree import Element

  When switching over code from ElementTree to etree, and you're using
  the package name prefix 'ElementTree', you can do the following::

    # instead of
    from elementtree import ElementTree
    # use
    from lxml import etree as ElementTree

* ElementTree has a bug when serializing an empty Comment (no text
  argument given) to XML, etree serializes this successfully.

* When trying to set a subelement using __setitem__ that is in fact
  not an Element but some other object, etree raises a TypeError, and
  ElementTree raises an AssertionError.

* ElementTree ignores comments when parsing XML, while etree will read
  them in and treat them as Comment elements.

* Because etree is built on top of libxml2, which is namespace prefix
  aware, etree preserves namespaces declarations and prefixes while
  ElementTree tends to come up with its own prefixes (ns0, ns1,
  etc). When no namespace prefix is given however, etree creates
  ElementTree style prefixes as well.
Something went wrong with that request. Please try again.