Re: Add XMLNamespaces to XMLElement

From: Jim Jones <jim(dot)jones(at)uni-muenster(dot)de>
To: Umar Hayat <postgresql(dot)wizard(at)gmail(dot)com>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Add XMLNamespaces to XMLElement
Date: 2025-01-15 20:35:41
Message-ID: 0e12b1d8-7958-4f0e-84dc-26b30ca4c716@uni-muenster.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Umar, Hi Pavel,

On 26.12.24 14:46, Jim Jones wrote:
> The idea of NO DEFAULT is pretty much to free an element (and its
> children) from a previous DEFAULT in the same scope.
>
> SELECT
>   xmlserialize(DOCUMENT
>     xmlelement(NAME "root",
>       xmlnamespaces(DEFAULT 'http:/x.y/ns1'),
>       xmlelement(NAME "foo",
>         xmlnamespaces(NO DEFAULT))
>   ) AS text INDENT);
>
>          xmlserialize         
> ------------------------------
>  <root xmlns="http:/x.y/ns1">+
>    <foo xmlns=""/>           +
>  </root>
> (1 row)

v3 is attached, now using xmlTextWriterWriteAttributeNS from libxml2 for
managing XML namespaces, instead of using xmlTextWriterWriteAttribute.
Libxml2 is quite lenient, allowing the duplication of default namespaces
within the same scope and even permitting NO DEFAULT namespaces when no
previous DEFAULT declaration has been made - both are semantically valid.

The crux now is finding the appropriate balance between accuracy and
user intent. In the context of PostgreSQL's xmlelement and
xmlnamespaces, I would argue that explicitly declared namespaces,
redundant or not, ought to be preserved. A user who intentionally
repeats a namespace declaration might have sound reasons for doing so,
like ensuring clarity, preserving compatibility with external XML
processors, or sticking to a specific schema. Silently omitting these
declarations could lead to confusion.

Pavel has tidied up the parser modifications - it's looking much neater
now. Many thanks for that!

Best, Jim

Attachment Content-Type Size
v3-0001-Add-XMLNamespaces-option-to-XMLElement.patch text/x-patch 58.0 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jeff Davis 2025-01-15 20:42:46 Re: Collation & ctype method table, and extension hooks
Previous Message Mahendra Singh Thalor 2025-01-15 20:10:27 Re: Non-text mode for pg_dumpall