Skip to Main Content

Database Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Optional element through XMLElement-XMLForest

remcobrandMar 22 2010 — edited Mar 22 2010
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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 19 2010
Added on Mar 22 2010
2 comments
1,525 views