VinnyChinn
VinnyChinn

Reputation: 49

Remove empty tags from xml using mule dataweave

I have xml and want to remove tag which has empty values.

Source:  
<wd:Worktag_Reference>
   <wd:ID wd:type="abc">RISK_STATE_GA</wd:ID>
</wd:Worktag_Reference>
<wd:Worktag_Reference>
    <wd:ID wd:type="abcd"/>
</wd:Worktag_Reference>
<wd:Worktag_Reference>
    <wd:ID wd:type="abcde">LC011</wd:ID>
</wd:Worktag_Reference>

and I want output like this

Result:  
<wd:Worktag_Reference>
   <wd:ID wd:type="abc">RISK_STATE_GA</wd:ID>
</wd:Worktag_Reference>
<wd:Worktag_Reference>
    <wd:ID wd:type="abcde">LC011</wd:ID>
</wd:Worktag_Reference>

Upvotes: 0

Views: 2900

Answers (2)

machaval
machaval

Reputation: 5059

You can use the filterObject function and remove the ones that their value is null. Also in my example I added the a tag name root as your xml was not valid

payload.root filterObject ((value, key, index) -> value.ID != null)

Upvotes: 1

Ranveer
Ranveer

Reputation: 35

You can use skipNullOn="everywhere" in Data weave.

Upvotes: 0

Related Questions