Debian Codegraph @

docs/configuration.rst

raw
1 Configuration
2 ==============
3
4 ElementTree configuration
5 --------------------------
6
7 By default, fastkml uses the standard libraries
8 ``xml.etree.ElementTree`` or, if installed, ``lxml.etree``
9 as its parser, but you can change this by setting the
10 ``fastkml.config.etree`` module variable to a different
11 implementation.
12
13 E.g. if you have lxml installed, but you want to use the
14 standard ``xml.etree.ElementTree``, you can do this:
15
16 .. code-block:: pycon
17
18 >>> import fastkml.config
19 >>> import xml.etree.ElementTree
20 >>> fastkml.config.set_etree_implementation(xml.etree.ElementTree)
21 >>> fastkml.config.set_default_namespaces()
22
23 You can pass any module that implements the ``ElementTree`` interface
24 to the ``set_etree_implementation`` function.
25
26 .. code-block:: pycon
27
28 >>> import fastkml.config
29 >>> import lxml.etree
30 >>> fastkml.config.set_etree_implementation(lxml.etree)
31
32 Registering additional namespaces
33 ----------------------------------
34 The ``fastkml.config.set_default_namespaces`` function registers
35 the ``kml``, ``gx`` and ``atom`` namespaces with the ``ElementTree``.
36 You can add any other namespaces you want to use by calling
37 ``fastkml.config.register_namespace`` with the namespace prefix and
38 the namespace URI.
39
40 .. code-block:: pycon
41
42 >>> import fastkml.config
43 >>> fastkml.config.register_namespaces(foo="http://foo.com")
44 >>> fastkml.config.set_default_namespaces()