%dw 2.0
output application/xml
---
users: {
(payload.users mapObject {
user: {
personal_information: $.personal_information - "ssn",
login_information: $.login_information - "password"
}
})
}
Exclude Fields from the Output
DataWeave 2.2 is compatible and bundled with Mule 4.2. This version of Mule reached its End of Life on May 2, 2023, when Extended Support ended. Deployments of new applications to CloudHub that use this version of Mule are no longer allowed. Only in-place updates to applications are permitted. MuleSoft recommends that you upgrade to the latest version of Mule 4 that is in Standard Support so that your applications run with the latest fixes and security enhancements. |
This DataWeave example excludes specific XML elements from the output. You might
perform a task like this to remove sensitive data.
Before you begin, note that DataWeave version 2 (%dw 2.0
) is for Mule 4 apps. For a
Mule 3 app, refer to DataWeave 1.0
(%dw 1.0
) examples,
within the Mule 3.9 documentation set. For other Mule versions, you can use
the Mule Runtime version selector in the table of contents.
The example uses these functions:
-
-
to remove specifickey:value
pairs (here, thessn
andpassword
XML elements). -
mapObject
to go through the XML elements.
<users>
<user>
<personal_information>
<first_name>Emiliano</first_name>
<middle_name>Romoaldo</middle_name>
<last_name>Lesende</last_name>
<ssn>001-08-84382</ssn>
</personal_information>
<login_information>
<username>3miliano</username>
<password>mypassword1234</password>
</login_information>
</user>
<user>
<personal_information>
<first_name>Mariano</first_name>
<middle_name>Toribio</middle_name>
<last_name>de Achaval</last_name>
<ssn>002-05-34738</ssn>
</personal_information>
<login_information>
<username>machaval</username>
<password>mypassword4321</password>
</login_information>
</user>
</users>
<?xml version="1.0" encoding="UTF-8"?>
<users>
<user>
<personal_information>
<first_name>Emiliano</first_name>
<middle_name>Romoaldo</middle_name>
<last_name>Lesende</last_name>
</personal_information>
<login_information>
<username>3miliano</username>
</login_information>
</user>
<user>
<personal_information>
<first_name>Mariano</first_name>
<middle_name>Toribio</middle_name>
<last_name>de Achaval</last_name>
</personal_information>
<login_information>
<username>machaval</username>
</login_information>
</user>
</users>