[XML Records] Help with structure XmlToRecordList
xml-records
Forge component by Afonso Carvalho
Application Type
Traditional Web

Hello everybody,

I'm trying to consume an API and need a structure that accepts this XML, but I'm having a lot of problems.

Initially I generated JSON (https://www.freeformatter.com/xml-to-json-converter.html) from XML (https://legis.senado.leg.br/dadosabertos/dados/MesaSenado.xml) and added a structure from JSON.


it didn't work and i got the error: The current node (xml) does not match the record definition

I followed the documentation (https://www.outsystems.com/forge/Component_Documentation.aspx?ProjectId=153&ProjectName=xml-records), but unfortunately I couldn't create a recordlist as expected.


Could you please guide me? Thank you very much in advance.

Solution

Hello @Bruno Menezes Noronha,

Even with the correct Structure, the "XML Records" component will fail for the following reason.
The Parent node and Child node, both have the same name - 'Cargo'.

I am not aware of any properties or settings within the "XML Records" component to deal with structures where a parent and child node have the same name.


The only work around I am aware of is to rename one of the Parent / Child nodes. For demonstration purposes I have renamed the child 'cargo' element to 'cargo1' as shown below, in both the XML file and the Structure.

The xml file with the renamed 'Cargo1' nodes is imported under the Data tab under Resources:

When you run the oml and click on 'Parse', you will see a list of cargo's to demonstrate that the logic works as long as the parent-child nodes have unique names and the right structure is defined. 


Hope this helps,

Regards,

AJ

ParseXML_Colegiados.oml

Hey @AJ. 

Thank you very much.

I managed to implement your solution in my scenario.

mvp_badge
MVP

Hi Bruno,

Can you share both your exact record definition and the XML?

Hi Kilian,

This is the variable that receives the XML.

When debugging, the return of the request (response of GET https://legis.senado.leg.br/dadosabertos/dados/MesaSenado.xml) made to the API has this result:

Thx for all.

Solution

Hello @Bruno Menezes Noronha,

Even with the correct Structure, the "XML Records" component will fail for the following reason.
The Parent node and Child node, both have the same name - 'Cargo'.

I am not aware of any properties or settings within the "XML Records" component to deal with structures where a parent and child node have the same name.


The only work around I am aware of is to rename one of the Parent / Child nodes. For demonstration purposes I have renamed the child 'cargo' element to 'cargo1' as shown below, in both the XML file and the Structure.

The xml file with the renamed 'Cargo1' nodes is imported under the Data tab under Resources:

When you run the oml and click on 'Parse', you will see a list of cargo's to demonstrate that the logic works as long as the parent-child nodes have unique names and the right structure is defined. 


Hope this helps,

Regards,

AJ

ParseXML_Colegiados.oml

Hey @AJ. 

Thank you very much.

I managed to implement your solution in my scenario.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.