JSONtoXML policy namespace issue

Hi,

I would like to convert directly the JSON request to XML request, while doing that in JSON to XML policy I would like to add the namespace for the generated XML. Also for the generated XML I don't need the processing instructions(<?xml version="1.0" encoding="UTF-8"?>). I have tried adding the namespace using NamespaceBlockName by directly giving the value of the namespace value in the JSON to XML policy but didn't work.Could you please suggest how to fix this.

Thanks

Tiru

0 2 310
2 REPLIES 2

as I always suggest, it's better to show what you're doing. Show the policy configuration, and show an example of the input, and show an example of the output.

Here's an example.

Suppose your input is this:

{
    "population": {
        "person": "John Smith",
        "exp:person": "Pedro Cabral"
    }
}

If you modify the JSON to be like this:

{
    "population": {
      "#namespaces" : {
        "$default": "http://www.w3.org/1999/people",
        "exp": "http://www.w3.org/1999/explorers"
      },
      "person": "John Smith",
      "exp:person": "Pedro Cabral"
    }
}


And then use this policy configuration:

<JSONToXML name='JSONToXML-2'>
  <Source>request</Source>
  <OutputVariable>request</OutputVariable>
  <Options>
    <NamespaceBlockName>#namespaces</NamespaceBlockName>
    <DefaultNamespaceNodeName>$default</DefaultNamespaceNodeName>
    <NamespaceSeparator>:</NamespaceSeparator>
  </Options>
</JSONToXML>

Then you get this result:

<?xml version="1.0" encoding="UTF-8"?><population xmlns="http://www.w3.org/1999/people" xmlns:exp="http://www.w3.org/1999/explorers"><person>John Smith</person><exp:person>Pedro Cabral</exp:person></population>

In the near future you will be able to use this policy config:

<JSONToXML name='JSONToXML-2'>
  <Source>request</Source>
  <OutputVariable>request</OutputVariable>
  <Options>
    <NamespaceBlockName>#namespaces</NamespaceBlockName>
    <DefaultNamespaceNodeName>$default</DefaultNamespaceNodeName>
    <NamespaceSeparator>:</NamespaceSeparator>
    <Indent>true</Indent>
    <OmitXmlDeclaration>true</OmitXmlDeclaration>
  </Options>
</JSONToXML>

to get the output with indenting, and without the XML declaration:

<population xmlns="http://www.w3.org/1999/people" xmlns:exp="http://www.w3.org/1999/explorers">
  <person>John Smith</person>
  <exp:person>Pedro Cabral</exp:person>
</population>

Coming soon!