cancel
Showing results for 
Search instead for 
Did you mean: 

Omit attributes in XML if null

0 Kudos

Hi,

I have a requirement to write table data into xml. I am trying to find out how to omit null values from writing on the xml.

As per the xml schema definition there are few attributes which either of them needs to be populated.

For example:

Attribute 'Income' if there is a value present then pass that value to this attribute, if not then populate value 'True' to attribute 'IncomeNA'

So at any given time only one attribute will be populated and active.

My mapping goes like this in query transformation

Income on xml -- direct mapping -- 'income' from table

IncomeNA on xml -- if 'Income' is null then 'True' else null.

If income is populated with positive value I don't want to write IncomeNA on to xml. I only want to write IncomeNA on to xml when Income is null.

I was told there is a way to omit null values writing on to xml but not sure how we do it on SAP BODS. Suggestions please?

Accepted Solutions (0)

Answers (1)

Answers (1)

0 Kudos

When the xml elements are defined under <choice> tags then either of the elements present under this tag can be populated ignoring rest of the elements. So in the above example if 'income' and 'incomeNA' is present under <choice> like this

<choice>

<income>..</income>

<incomeNA>...<incomeNA>

</choice>

then if income is populated then incomeNA can be populated with null or can be ignored.

I achieved this in query transformation

income - direct mapping of table.income column

incomeNA - ifthenelse(table.income is null, 'true', null)

so automatically 'null' attributes are ignored while writing on to xml file. so job done for my requirement.