API Connect

 View Only

 namespace management

Jimmy Perilla's profile image
Jimmy Perilla posted Wed May 21, 2025 12:00 AM

Hello team.

I have a question.
I'm developing an API that receives a message in JSON format. Using a map node, I'm mapping and transforming JSON to XML (since my backend only receives the message in XML). However, the XML format the backend expects is the following:
<?xml version="1.0" encoding="utf-8"?>
  <message xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://google.net/schema" xsi:schemaLocation="/www/services/xxx/ABC/webcontent/schemas/RQ123.xsd">
<version>1.0</version>
<header>
<operationCode>123</operationCode>
<origin>
<country>CO</country>
</origin>
<target>
<country>CO</country>
</target>
</header>
<key>
<grossAmount>
</grossAmount>
<documentsList>
<document>
</document>
<document>
</document>
</documentsList>
<serviceScript>SOAPXML123.XML</serviceScript>
</key>
</message>
and The JSON structure sent by the user is the following:
{
"grossAmount": {
"currency": {
"code": "CO",
"operationCode": "123"
},
"amount": 1
},
"maxDueDate": "2025-07-30",
"documents": [
"amount": 1
]
}

I need to know how I can include that namespace '<message xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://google.net/schema" xsi:schemaLocation="/www/services/xxx/ABC/webcontent/schemas/RQ123.xsd">'
in the output of the message? Because in all my tests I can't include those values ​​within the namespace since they are constants, they never change.

I'm using an XSL node after mapping with the map node, where I'm using the following code:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
exclude-result-prefixes="xsl xsi">

<xsl:output method="xml" indent="yes"/>

<!-- Copy everything as is -->
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>

<!-- Replace any root node named "message" regardless namespace -->
<xsl:template match="/*">
<message xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://bac.net/schema"
xsi:schemaLocation="/www/services/bco/cus/webcontent/schemas/RQ09243.xsd">
<xsl:apply-templates select="@* | node()"/>
</message>
</xsl:template>

</xsl:stylesheet>

But I keep getting the XML response without the expected namespace.

Any suggestions? It would be very helpful.
Thanks

Steve Linn's profile image
Steve Linn

Hi Jimmy,

The map policy only generates namespace definitions that the output schema specifies are needed.  You should be able to generate the default namespace by specifying in your root element an xml property that does not have a prefix, only the namespace uri.  However, the xsi namespace isn't used by any of your XML elements, so map won't produce it, I'm assuming there isn't a polymorphic element that would use the xsi namespace in an attribute of the element?

As for your xslt, you're matching on /*.  Try matching on only / or on the element name message.

Best Regards,
Steve Linn