You have said that XMLFOREST has something which ignores nulls, what's that? Will you please provide an example ?
I was partially wrong - XMLFOREST ignore null always
postgres=# select xmlforest(10 as a,20 as b,null as c); xmlforest -------------------- <a>10</a><b>20</b> (1 row)
so if you would to empty elements, you should to use xmlelement and xmlconcat
postgres=# select xmlconcat(xmlforest(10 as a,20 as b), xmlelement(name c, null)); xmlconcat ------------------------ <a>10</a><b>20</b><c/> (1 row)
I am NOT sure, but here you are trying to omit entire field from the output when its value is NULL. But that will add an extra efforts at other end which is using output of this. That application need to know all fields and then need to replace NULL values for missing fields. However we have an optional argument for ignoring nulls and thus we are safe. Application will use as per its choice.
with my patch, you can do decision - lot of REST services doesn't distinguishes between empty and missing tag - and some developers prefer remove empty tags due less size of message.
Well, apart from that, tried reviewing the patch. Patch was applied but make failed with following error.