Using the XML serializer: how to namespace the elements?

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:

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

Hi @robin.speekenbrink

Have you tried to check this?

Or is it different for your needs?

This doesnt consider the namespace prefix…

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

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

and then after serializing alter the output via a replace:


Where i’d have to add the namespace in the “Replace” field.
Or as @-attribute to the root element in my json:

{
  "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...>

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>

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?

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 :wink: (but thankfully none are SOAP)