when a query is executed.
+Writing a custom loader: XML
+----------------------------
+
+Psycopg doesn't provide a loader for the XML data type because there are just
+too many ways of handling it in Python. Creating a loader to parse the
+`PostgreSQL xml type`__ to `~xml.etree.ElementTree` is very simple, using the
+`psycopg.adapt.Loader` base class.
+
+Note that it is possible to use a `~psycopg.types.TypesRegistry`, exposed by
+any `~psycopg.abc.AdaptContext`, to obtain information on builtin types, or
+extension types if they have been registered::
+
+ >>> import xml.etree.ElementTree as ET
+ >>> from psycopg.adapt import Loader
+
+ >>> # Create a class setting the `format` and implementing the `load()` method.
+ >>> class XmlLoader(Loader):
+ ... format = psycopg.pq.Format.TEXT
+ ... def load(self, data):
+ ... return ET.fromstring(data)
+
+ >>> # Register the loader on the adapters of a context.
+ >>> conn.adapters.register_loader(conn.adapters.types["xml"].oid, XmlLoader)
+
+ >>> # Now just query the database returning XML data.
+ >>> cur = conn.execute(
+ ... """select XMLPARSE (DOCUMENT '
+ ... <?xml version="1.0"?>
+ ... <book><title>Manual</title><chapter>...</chapter></book>')
+ ... """)
+
+ >>> cur.fetchone()[0]
+ <Element 'book' at 0x7ffb55142ef0>
+
+.. __: https://www.postgresql.org/docs/current/datatype-xml.html
+
+
Example: PostgreSQL numeric to Python float
-------------------------------------------
.. data:: adapters
- The global, default adapters map establishing how Python and PostgreSQL
- types are converted into each other. This map is used as template when new
- connections are created, using `psycopg.connect()`.
+ The default adapters map establishing how Python and PostgreSQL types are
+ converted into each other.
+
+ This map is used as template when new connections are created, using
+ `psycopg.connect()`. Its `~psycopg.adapt.AdaptersMap.types` attribute is a
+ `~psycopg.types.TypesRegistry` containing information about every
+ PostgreSQL builtin type, useful for adaptation customisation (see
+ :ref:`adaptation`)::
+
+ >>> psycopg.adapters.types["int4"]
+ <TypeInfo: int4 (oid: 23, array oid: 1007)>
:type: `~psycopg.adapt.AdaptersMap`
.. autoclass:: TypesRegistry
+ `!TypeRegistry` instances are typically exposed by
+ `~psycopg.adapt.AdaptersMap` objects in adapt contexts such as
+ `~psycopg.Connection` or `~psycopg.Cursor` (e.g. `!conn.adapters.types`).
+
+ The global registry, from which the others inherit from, is available as
+ `psycopg.adapters`\ ``.types``.
+
.. _numeric-wrappers: