01-18-2024 05:57 AM
Hi, I am building a SDK Connector that calls an API with XML payload.
I am following the Handling XML documentation
However, I want to know how I can exclude the xml tag whenever the input value is not provided. Is there a way we can do that?
For example, I have 2 optional input fields: key1 and key2
And I am using this code to create the xml payload
"content": [
{
"data1": [{ "content!": input["key1"] }],
"data2": [{ "content!": input["key2"] }]
}
]
And I am expecting to get this xml
<content>
<data1>key1Value</data1>
<data2>key2Value</data1>
<content>
However, when the input for key2 is not provided, I want to get this xml:
<content>
<data1>key1Value</data1>
<content>
Solved! Go to Solution.
01-18-2024 08:48 AM
Hi @ricardomatsumot,
You need to build your structure with some conditions before converting it into XML. For example like this.
object = {}
object['data1'] = _input['key1'] if _input['key1'].present?
object['data2'] = _input['key2'] if _input['key2'].present?
Hope this helps you!
Cheers,
Chris
01-18-2024 08:48 AM
Hi @ricardomatsumot,
You need to build your structure with some conditions before converting it into XML. For example like this.
object = {}
object['data1'] = _input['key1'] if _input['key1'].present?
object['data2'] = _input['key2'] if _input['key2'].present?
Hope this helps you!
Cheers,
Chris
01-18-2024 09:22 AM
Thanks Chris!! It worked pretty well