From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Modernize our parsing of XML data in CONTENT mode.
Date: Thu, 15 Oct 2026 14:31:29 +0000
Message-ID: <E1xHMUT-00000001kFC-2HGC@gemulon.postgresql.org> (raw)
Modernize our parsing of XML data in CONTENT mode.
The main goal of this patch is to get rid of our use of
xmlKeepBlanksDefault, which libxml2 has deprecated.
To do that, we want to use xmlParseInNodeContext instead of
xmlParseBalancedChunkMemory, so that we can pass an options
mask that includes XML_PARSE_NOBLANKS.
xmlParseInNodeContext wants an xmlNode rather than an xmlDoc as
context. This gives us an opportunity for simplification though:
we can make that node be a dummy root node for xml_parse's result
document, and then attach the content node(s) as children of the root,
essentially moving the data structure hack in xmltotext_with_options
into xml_parse. The main benefit of this is that callers no longer
need to free the content node list separately; freeing the document is
sufficient. (There were error paths in xmltotext_with_options that
I think would have leaked that list, though they could only be
reached in OOM or similar conditions.)
We also do some fooling with doc->encoding, to be bug-compatible
with our previous behavior on as many libxml2 versions as practical.
Some small discrepancies with previous behavior are known with older
libxml2 versions. Therefore, it seems inadvisable to back-patch this,
at least not before it's gotten a good deal of field experience.
Author: Tom Lane <tgl@sss.pgh.pa.us>
Fix-suggested-by: Andrew Dunstan <andrew@dunslane.net>
Reviewed-by: Rui Zhao <zhaorui126@gmail.com>
Discussion: https://postgr.es/m/ZR2PPFF1830B8772632FA23847D7482168FD2C62@ZR2PPFF1830B877.CHEP278.PROD.OUTLOOK.CO...
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/30d4a6daac8b61fd18dfe0d990d00943a170e48b
Modified Files
--------------
src/backend/utils/adt/xml.c | 156 ++++++++++++++++++++------------------
src/test/regress/expected/xml.out | 29 +++++++
src/test/regress/sql/xml.sql | 30 ++++++++
3 files changed, 143 insertions(+), 72 deletions(-)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: tgl@sss.pgh.pa.us
Subject: Re: pgsql: Modernize our parsing of XML data in CONTENT mode.
In-Reply-To: <E1xHMUT-00000001kFC-2HGC@gemulon.postgresql.org>
References: <E1xHMUT-00000001kFC-2HGC@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox