Nav

Example: Include XML Namespaces

This example defines different namespaces in the header and then references them on each tag.

This example uses:

  • namespace definitions in the header.

  • @ to define other attributes in an XML element.

DataWeave

         
      
1
2
3
4
5
6
7
8
9
10
%dw 2.0
output application/xml
ns orders http://www.acme.com/shemas/Orders
ns stores http://www.acme.com/shemas/Stores
---
root:
    orders#orders: {
        stores#shipNodeId: "SF01",
        stores#shipNodeId @(shipsVia:"LA01"): "NY03"
        }
Output

         
      
1
2
3
4
5
6
7
<?xml version='1.0' encoding='US-ASCII'?>
<root>
  <po:order xmlns:po="http://www.acme.com/shemas/Orders">
    <store:shipNodeId xmlns:store="http://www.acme.com/shemas/Stores">SF01</store:shipNodeId>
    <store:shipNodeId xmlns:store="http://www.acme.com/shemas/Stores" shipsVia="LA01">NY03</store:shipNodeId>
  </po:order>
</root>

In this topic: