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 kwargs['nsmap'] = NSMAP
13 return etree.Element(*args, **kwargs)
17 # normal cElementTree install
18 import cElementTree as etree
20 # normal ElementTree install
21 import elementtree.ElementTree as etree
24 register_namespace = etree.register_namespace
25 except AttributeError:
26 def register_namespace(prefix, uri):
27 etree._namespace_map[uri] = prefix
29 def ElementRoot(*args, **kwargs):
30 return etree.Element(*args, **kwargs)
32 __all__ = ('etree', 'register_namespace', 'ElementRoot')