# Using the XML serializer: how to namespace the elements?

**URL:** <https://forum.alumio.com/t/using-the-xml-serializer-how-to-namespace-the-elements/887>\
**Category:** Data Transformers\
**Created:** [November 23, 2023, 2:36pm UTC](https://forum.alumio.com/t/using-the-xml-serializer-how-to-namespace-the-elements/887 "2023-11-23T14:36:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![robin.speekenbrink](https://forum.alumio.com/user_avatar/forum.alumio.com/robin.speekenbrink/32/1091_2.png) [@robin.speekenbrink](https://forum.alumio.com/u/robin.speekenbrink)\
**Post date:** [November 23, 2023, 2:36pm UTC](https://forum.alumio.com/t/using-the-xml-serializer-how-to-namespace-the-elements/887/1 "2023-11-23T14:36:31Z")

</div>

When serializing a JSON file to XML how can I utilize added namespaces to my result?  
i.e. I’d like to build the following:

```auto
<xml xmlns:cac="consider some valid namespace">
<result>
<cac:test>foo</cac:test>
<test>bar</test>
</result>

```

---

<div class="post-metadata">

**Author:** ![r.candrian](https://forum.alumio.com/user_avatar/forum.alumio.com/r.candrian/32/235_2.png) [@r.candrian](https://forum.alumio.com/u/r.candrian)\
**Post date:** [November 24, 2023, 8:48am UTC](https://forum.alumio.com/t/using-the-xml-serializer-how-to-namespace-the-elements/887/2 "2023-11-24T08:48:47Z")

</div>

Hi @robin.speekenbrink

Have you tried to check this?

> [@How to map with Serialize: XML](https://forum.alumio.com/t/how-to-map-with-serialize-xml/356):
>
> Table of contents Use case 1 Use case 2 Use Case 1 Basically, Alumio uses the JSON data type in every transformer. While some systems sometimes only accept XML, you can convert the JSON data into XML by using the Value Mapper transformer and the Serialize: XML mapper. Guide 1. Set attributes to an element Please have a look at the below XML data. \<?xml version="1.0"?\> \<data attr1="value 1" attr2="value 2"\> \<content\>this is content\</content\> \</data\> …

Or is it different for your needs?

---

<div class="post-metadata">

**Author:** ![robin.speekenbrink](https://forum.alumio.com/user_avatar/forum.alumio.com/robin.speekenbrink/32/1091_2.png) [@robin.speekenbrink](https://forum.alumio.com/u/robin.speekenbrink)\
**Post date:** [November 24, 2023, 9:12am UTC](https://forum.alumio.com/t/using-the-xml-serializer-how-to-namespace-the-elements/887/3 "2023-11-24T09:12:01Z")

</div>

This doesnt consider the namespace prefix…

From what i understand i’ll have to prefix the namespaces myself per key (as my example):

```auto
{
  "result": {
    "cac:test": "foo",
    "test": "bar"
  }
}

```

and then after serializing alter the output via a replace:

 ![image](https://alumio-forum.s3.dualstack.eu-central-1.amazonaws.com/uploads/original/2X/7/7446c404194866b47b43794f32b553c12f245542.png)  
Where i’d have to add the namespace in the “Replace” field.  
Or as @-attribute to the root element in my json:

```auto
{
  "result": {
    "@xmlns:cac": "consider some valid namespace",
    "cac:test": "foo",
    "test": "bar"
  }
}

```

(which wold move the namespace definition from `<xml>` to `<xml><result xmlns:cac...>`

---

<div class="post-metadata">

**Author:** ![robin.speekenbrink](https://forum.alumio.com/user_avatar/forum.alumio.com/robin.speekenbrink/32/1091_2.png) [@robin.speekenbrink](https://forum.alumio.com/u/robin.speekenbrink)\
**Post date:** [November 24, 2023, 9:13am UTC](https://forum.alumio.com/t/using-the-xml-serializer-how-to-namespace-the-elements/887/4 "2023-11-24T09:13:12Z")

</div>

Which also brings me to another gripe i have with the serializer as currently: the encoding… I always have to add a post-replace mapper to add in the encoding attribute to the `<xml>`…

---

<div class="post-metadata">

**Author:** ![Gugi](https://forum.alumio.com/user_avatar/forum.alumio.com/gugi/32/236_2.png) [@Gugi](https://forum.alumio.com/u/Gugi)\
**Post date:** [December 12, 2023, 8:49am UTC](https://forum.alumio.com/t/using-the-xml-serializer-how-to-namespace-the-elements/887/5 "2023-12-12T08:49:23Z")

</div>

Hi @robin.speekenbrink

We are sorry for the late reply. Unfortunately, the Serialize: XML mapper doesn’t support adding namespace yet. As you may already know, you should add the namespace manually for every attribute and element in the JSON format.

Anyway, could you please let us know whether you are trying to call a SOAP service? Or, is it just a REST with namespace in the XML payload?

---

<div class="post-metadata">

**Author:** ![robin.speekenbrink](https://forum.alumio.com/user_avatar/forum.alumio.com/robin.speekenbrink/32/1091_2.png) [@robin.speekenbrink](https://forum.alumio.com/u/robin.speekenbrink)\
**Post date:** [December 12, 2023, 9:09am UTC](https://forum.alumio.com/t/using-the-xml-serializer-how-to-namespace-the-elements/887/6 "2023-12-12T09:09:13Z")

</div>

We’ve worked around the issue by utilizing a combination of both adding namespace prefixes to _all_ json elements, adding the namespace attributes to the root element and utilizing the replace-transformer to make sure the XML document has the right encoding attributes and such…

Also we drop the XML in an e-mail attachment, FTP / HTTP (rest) endpoint and write it out to a separate FTP storage for archival purposes. So it’s a myriad of output 😉 (but thankfully none are SOAP)
