Re: [BUG?] XMLSERIALIZE( ... INDENT) won't work with blank nodes
Jim Jones <jim.jones@uni-muenster.de>
From: Jim Jones <jim.jones@uni-muenster.de>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>,
Pavel Stehule <pavel.stehule@gmail.com>
Date: 2024-09-06T22:46:06Z
Lists: pgsql-hackers
Attachments
- v2-0002-Bug-fix-remove-default-trailing-newline-from-XMLS.patch (text/x-patch) patch v2-0002
- v2-0001-Bug-fix-for-XMLSERIALIZE-.INDENT-for-xml-containi.patch (text/x-patch) patch v2-0001
Hi Tom On 06.09.24 18:34, Tom Lane wrote: > I think it'd be quite foolish to assume that every extant and future > version of libxml2 will share this glitch. Probably should use > logic more like pg_strip_crlf(), although we can't use that directly. Makes sense. I Introduced this logic in the end of xmltotext_with_options() in case it was called with INDENT and DOCUMENT type xml string. SELECT xmlserialize(DOCUMENT '<foo><bar>42</bar></foo>' AS text INDENT); xmlserialize ----------------- <foo> + <bar>42</bar>+ </foo> (1 row) The regression tests were updated accordingly - see patch v2-0002. > Would it ever be the case that trailing whitespace would be valid > data? In a bit of testing, it seems like that could be true in > CONTENT mode but not DOCUMENT mode. Yes, in case of CONTENT it is valid data and it will be preserved, as CONTENT can be pretty much anything. SELECT xmlserialize(CONTENT E'<foo><bar>42</bar></foo>\n\n\t\t\t' AS text INDENT); xmlserialize -------------------------- <foo> + <bar>42</bar> + </foo> + + (1 row) With DOCUMENT it is superfluous and should be removed after indentation. IIRC there's an xmlSaveToBuffer option called XML_SAVE_WSNONSIG that can be used to preserve it. Thanks Best, Jim
Commits
-
Fix some whitespace issues in XMLSERIALIZE(... INDENT).
- bccca780eef9 18.0 landed
- 946f150aa180 17.0 landed
- 06c285018a81 16.5 landed