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)
18 import xml.etree.cElementTree as etree
22 import xml.etree.ElementTree as etree
25 # normal cElementTree install
26 import cElementTree as etree
28 # normal ElementTree install
29 import elementtree.ElementTree as etree
32 register_namespace = ET.register_namespace
33 except AttributeError:
34 def register_namespace(prefix, uri):
35 ET._namespace_map[uri] = prefix
37 def ElementRoot(*args, **kwargs):
38 return etree.Element(*args, **kwargs)
40 __all__ = ('etree', 'register_namespace', 'ElementRoot')