Hi Sandile,
I'm used to using the map policy. Click on the pencil to create a input or output, and then choose the inline schema choice for the type. You'll be presented a dialog where you can provide sample XML with a namespace, for example,
click on the generate button to get the actual schema
Best Regards,
Steve Linn
------------------------------
Steve Linn
Senior Consulting I/T Specialist
IBM
------------------------------
Original Message:
Sent: Fri June 30, 2023 06:59 AM
From: Sandile Ngubeni
Subject: API Connect v10: Convert JSON request.body to XML with namespaces
Hi Steve,
Is there a sample project I can look at for this solution?
------------------------------
Sandile Ngubeni
Original Message:
Sent: Wed October 05, 2022 09:04 AM
From: Steve Linn
Subject: API Connect v10: Convert JSON request.body to XML with namespaces
Hi Henri,
XML output from a map policy is all based upon the output schema. A simple way would be to use an inline schema for the XML output where you specify a sample XML with the desired namespaces for the elements that need namespaces. The map policy will map the JSON and the schema provides the XML structure for the values to be output.
Best Regards,
Steve Linn
------------------------------
Steve Linn
Senior Consulting I/T Specialist
IBM
Original Message:
Sent: Thu September 29, 2022 09:20 AM
From: Henri Unruh
Subject: API Connect v10: Convert JSON request.body to XML with namespaces
Thank you for your response. However I have not yet found a way to do this via Map policy.
How would that map look like? Hardcode the namespace to the root element somehow?
Regards,
------------------------------
Henri Unruh
Original Message:
Sent: Wed September 28, 2022 08:59 PM
From: Samir Almousawi
Subject: API Connect v10: Convert JSON request.body to XML with namespaces
I think this can be achieved by Map assemble. To get the sample, I used a free JSON to XML (or vise versa) with namespaces (freeformatter.com)
------------------------------
Samir Almousawi
Original Message:
Sent: Wed September 28, 2022 05:33 AM
From: Henri Unruh
Subject: API Connect v10: Convert JSON request.body to XML with namespaces
Hi guys,
I´m trying to convert an incoming JSON request.body to XML format with namespaces.
The XML element TransportOrder should look like this after conversion from JSON:
<yq1:TransportOrder xmlns:yq1="urn:XYZ.de:logistics:transportorder"
>
Using the parse and json-to-xml policies in the assembly only leads to the namespace being appended to the TransportOrder element as:
<TransportOrder> <data>some data</data> <a>some data</a> <b>some data</b> <c>some data</c> <_xmlns_yq1>urn:XYZ.de:logistics:transportorder</_xmlns_yq1></TransportOrder>
How should the original request in JSON look like so that the namespace xmlns:yq1="urn:XYZ.de:logistics:transportorder"
is added to the TransportOrder element?
Is there a way to achieve this without using a map policy?
Thanks and best regards,
Henri
------------------------------
Henri Unruh
------------------------------