Skip to main content

Abstracts out the implementation of elementtree behind the zope component architecture. And provides helper functions for testing XML output in tests.

Project description


z3c.etree provides some mechanisms (a common interface) for integrating any ElementTree engine with the Zope component architecture. This allows applications to look up a engine against this interface. As such this package does not implement the ElementTree API.

z3c.etree also provides a set of utilities that can be used to make testing XML output in doctests easier. This functionality can also be called from a python based unit test via the assertXMLEqual method.


>>> import z3c.etree
>>> import z3c.etree.testing
>>> engine = z3c.etree.testing.etreeSetup()

Here are some examples for how to use z3c.etree with your own code.

To generate a Element object with the tag DAV:getcontenttype all we have to do is:

>>> etree = z3c.etree.getEngine()
>>> elem = etree.Element("{DAV:}getcontenttype")
>>> elem #doctest:+ELLIPSIS
<Element ...>
>>> z3c.etree.testing.assertXMLEqual(etree.tostring(elem), """
...    <getcontenttype xmlns="DAV:"/>""")

Now to add a value this element use just use the elem variable has the API suggests.

>>> elem.text = "text/plain"
>>> z3c.etree.testing.assertXMLEqual(etree.tostring(elem), """
...    <getcontenttype xmlns="DAV:">text/plain</getcontenttype>""")


>>> z3c.etree.testing.etreeTearDown()

Changes in z3c.etree


  • Bug: Fix Python 2.5 support.

  • Bug: Declared z3c as a namespace.

  • Implemented a way of comparing two XML fragments while ignoring the ordering of elements at the same level.

  • Allow the use of NORMALIZE_WHITESPACE with tag contents.


  • fix bug in getting access to the elementree engine


  • Start registering the elmenttree modules directly instead of using some proxy objects.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

z3c.etree-0.9.2.tar.gz (12.0 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page