CODI
CODI

Reputation: 173

Extract namespace

I am new to dataweave 2.0. I need help extracting an xml like below payload.

payload

<?xml version='1.0' encoding='UTF-8'?>
<ns:test xmlns:ns="http//sample">
  <test1 xmlns:ns1="http://sample1" ns1:firstKey="1234" secondKey="678" thirdKey="456"/>
</ns:test>

Need to Get: 1234.

What I tried: Dataweave Script

%dw 2.0
output application/xml
---
payload.test.test1.@firstKey

Upvotes: 0

Views: 457

Answers (1)

Salim Khan
Salim Khan

Reputation: 4303

What you have done is correct, however since you are outputting it as application/xml, you would need a root element. So something like this:

%dw 2.0
output application/xml
---
{
    a: payload.test.test1.@firstKey
}

However if you change your script output to application/json, it would work just fine.

enter image description here

Upvotes: 4

Related Questions