0
votes

Just want to know if anyway to remove an element from xml by dataweave, sample xml (payload) like this:

     <?xml version="1.0" encoding="UTF-8"?>
 <SampleData CreateDttm="2017-08-02T00:00:00">
          <Accounts>
             <Account ID="123">
                <PolicyHeaderTable PolicyID="EX20130002">
                   <WArchive>1</WArchive>
                   <PolicyNum>12345678</PolicyNum>
                    ... ...
                 </PolicyHeaderTable>
               </Account>
            </Accounts>
 </SampleData>  

I just want to remove "WArchive", note there are about 200 elements replaced by ellipses in code snippet. I have tried below remove function in dataweave but failed.

%dw 1.0
 %output application/xml
 ---
 //payload.SampleData.Accounts.Account.PolicyHeaderTable - "WArchive"
 //payload - payload.SampleData.Accounts.Account.PolicyHeaderTable.WArchive

Could anyone please suggest the transform code can be used in dataweaver? I understand xslt is able to handle this, but I prefer to use dataweaver if possible.

Thank you very much.

Best Regards, Robert

1

1 Answers

2
votes
Please find the below code which removes an xml element by remove(-) operator.

%dw 1.0
%output application/xml
---

"SampleData" : payload.SampleData mapObject {
            "Accounts" : $ mapObject {
                "Account" : $ mapObject {
                    "PolicyHeadeTable" : $ - "WArchive"
                }
            } 
        }