Re: Add XMLNamespaces to XMLElement
Pavel Stehule <pavel.stehule@gmail.com>
From: Pavel Stehule <pavel.stehule@gmail.com>
To: Jim Jones <jim.jones@uni-muenster.de>
Cc: Umar Hayat <postgresql.wizard@gmail.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2025-01-16T07:36:52Z
Lists: pgsql-hackers
Hi st 15. 1. 2025 v 21:35 odesílatel Jim Jones <jim.jones@uni-muenster.de> napsal: > 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. > > Now, I have not any objections against the code The patch has doc and enough regress tests The patching and compilation without problems make check-world passed I'll mark this patch as ready for committer > Pavel has tidied up the parser modifications - it's looking much neater > now. Many thanks for that! > It was a pleasure Regards Pavel > > Best, Jim > >