Skip to Content
0

Omit attributes in XML if null

Feb 22, 2017 at 10:30 AM

33

avatar image

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?

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Srinivas Kumar Mar 14, 2017 at 04:51 PM
0

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.

Share
10 |10000 characters needed characters left characters exceeded