-1

I have a XML like this below and i want to extract the attributes (example: externalid) of it using DataWeave.

"<?xml version="1.0" encoding="UTF-8"?>
<platformCore:record xmlns="urn:messages.platform.webservices.netsuite.com" xmlns:listRel="urn:relationships.lists.webservices.netsuite.com" xmlns:platformCore="urn:core.platform.webservices.netsuite.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" externalId="680" internalId="1426" xsi:type="listRel:Customer">
    <listRel:entityId>CUST611 Comercial Vega</listRel:entityId>
    <listRel:isPerson>false</listRel:isPerson>
</platformCore:record>"
aled
  • 21,330
  • 3
  • 27
  • 34

1 Answers1

1

Use the attribute selector on a key to get its attributes.

With an attribute name it will return the attribute value:

%dw 2.0
output application/json
ns platformCore urn:core.platform.webservices.netsuite.com
---
payload.platformCore#record.@externalId

Output:

"680"

Without a key name it returns an object with the names and values of all the attributes for that key:

%dw 2.0
output application/json
ns platformCore urn:core.platform.webservices.netsuite.com
---
payload.platformCore#record.@

Output:

{
  "externalId": "680",
  "internalId": "1426",
  "type": "listRel:Customer"
}

I'm using JSON for the output for clarity. If you are using the values later I would recommend to use output application/java to avoid duplicated parsing.

aled
  • 21,330
  • 3
  • 27
  • 34