Optional element through XMLElement-XMLForest
Part of the xml I need to generate looks like
<adres>
<straat1>Postbus 44415</straat1>
<straat2>Hoofdweg</straat2>
<postcode>9999 AK</postcode>
<plaats>Dordrecht</plaats>
</adres>
which I have translated to
XMLElement("adres",
XMLForest(e.addr1 AS "straat1",
e.addr2 AS "straat2",
e.zip AS "postcode",
e.city AS "plaats"))
But when all columns are null this translates to </adres>
which gives an error when I validate against the xsd I need to work against.
Best option would be to leave the adres-element out all together when all columns are null
I could achieve this by
(CASE when e.addr1 is NOT NULL OR e.addr2 IS NOT NULL OR e.zip IS NOT NULL OR e.city IS NOT NULL then
XMLElement("adres",
XMLForest(e.addr1 AS "straat1",
e.addr2 AS "straat2",
e.zip AS "postcode",
e.city AS "plaats")))
But somehow I get the idea this could be achieved more elegant.
I have another element which has even more forest-elements then this example so it would be nice if this can be achieved in an easier way