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