Hi Makers,
Do you know of any function or way to convert an array / a collection to a XML structure?
I cannot find any way or function for it and it is crucial for my situation (API of application I’m using).
If not - what do you think of such a function? Could it be useful for you? (example below)
I already proposed one function and this one is similar but very different the same time.
having such an input:
[
{
“a”: 1,
“b”: “alfa”,
“c”: [
{
“d”: “2024-01-01”,
“e”: 21.97
}
]
},
{
“a”: 2,
“b”: “beta”,
“c”: [
{
“d”: “2024-02-11”,
“e”: 21.97
},
{
“d”: “2024-02-12”,
“e”: 23.99
}
]
}
]
expecting such output:
[
“<id>1</id><name>alfa</name><pricings><pricing><date>2024-01-01</date><price>21.97</price></pricing></pricings>”,
“<id>2</id><name>beta</name><pricings><pricing><date>2024-02-11</date><price>21.97</price></pricing><pricing><date>2024-02-12</date><price>23.99</price></pricing></pricings>”
]
using such function:
convert_array_to_xml(input, collection_of_mappings);
with additional collection_of_mappings:
{
“a”: “id”,
“b”: “name”,
“c”: [“pricings”,“pricing”],
“d”: “date”,
“e”: “price”
}
Regards,
Johnny