Hello Team,
I'm fetching instance data from AWS through API since I was not moving forward through REST API method as it was giving Authorization Error. Then I found a component in Forge AWS Signature and with that I got a server action which gives response data in XML format.
I want that XML data format to be get converted and stored in my database entity.
I tried many ways but I'm not getting any success. I tried this component too XML Records but it is also not giving me any value.
Can anyone help me in this?
Hi Dev,
XML Records is usually the way to go if you have relatively simple record structures. If you have something more complex, you could also take a look at the XmlToJson asset, since JSON is better to handle than XML.
Hello Kilian,
Nice to talk to you again. I tried your component and also tried to convert XML data to Json and then Json to Structure.
As I need to run my action in every 5 minutes, so after every interval a updated XML will be fetched and that Data I want to insert in my database entity so that I can display it on screen.
Therefore, I created a server Action and tried your component but then too it giving me a long error like this.
This is my Server Action :
Please have a look.
Thank you.
The XML to JSON conversion has no idea of the structure of the XML, and so doesn't know whether something is an array or not if only one element is present. Therefore make sure you use the ArrayNodes input parameter of XmlToJson to list all the tags that contain arrays. The error you are getting shows that the JSON contains a single object instead of an array, and that's caused by not correctly flagging the arrays in the conversion.
I have also used array nodes something like this :
So is it correct?
And if I have to mention array nodes, then it would be a difficult task cause my actual XML file too complex and huge.
You only need to specify a node as ArrayNode if it can have more than one element, but sometimes only has a single element. E.g. this:
<book> <title>The OutSystems Bible</title> <author>D.E. Veloper</author> </book>
would generate the following JSON:
{ "book": { "title":"The OutSystems Bible", "author":"D.E. Veloper" } }
But e.g. this:
<book> <title>Cooperative OutSystems</title> <author>D.E. Veloper</author> <author>C.O. Author</author> </book>
{ "book":{ "title":"Cooperative OutSystems", "author":[ "D.E. Veloper", "C.O. Author" ] } }
So in that case, you'd add the "author" tag to the ArrayNodes (but not "title", as there can be only a single title). In that case, the first example would yield:
{ "book": { "title":"The OutSystems Bible", "author":[ "D.E. Veloper" ] } }
Thank you Kilian for such a brief explanation.
Now like you said, in my situation,
the following xml is something like this
And I haven't added arraynodes, so why it is giving me same error? could you please explain it?
Hi,
If I understand correctly what you need. You will have to create an entity with all XML structure fields. Then create a structure with same fields of XML file. Then convert the XML to record list and save the data on the Outsystems entity,
If you want to save the XML file content is a single entity attribute, then consider convert the XML to JSON, because JSON content size is smaller than XML. JSON is also more flexible than XML
Hello Nelson,
Thank you for your reply, I have attached my snapshots where I have tried XML to Json.
Please have a look and guide me where I am wrong.