1 # Import etree from anywhere
3 # lxml http://codespeak.net/lxml/
6 # Define register_namespace function and ElementRoot for proper serialization
8 def register_namespace(prefix, uri):
11 def ElementRoot(*args, **kwargs):
12 return etree.Element(*args, nsmap=NSMAP, **kwargs)
17 import xml.etree.cElementTree as etree
21 import xml.etree.ElementTree as etree
24 # normal cElementTree install
25 import cElementTree as etree
27 # normal ElementTree install
28 import elementtree.ElementTree as etree
31 register_namespace = ET.register_namespace
32 except AttributeError:
33 def register_namespace(prefix, uri):
34 ET._namespace_map[uri] = prefix
36 def ElementRoot(*args, **kwargs):
37 return etree.Element(*args, **kwargs)
39 __all__ = ('etree', 'register_namespace', 'ElementRoot')