Hello everyone,
I'm currently working on an application to convert standardized XML invoices into PDFs, and so far, it’s been working well. However, I’ve encountered a challenge with the CII format and need your help.
To give you some context, I initially based my structure on an example where a field is named GlobalID and contains an associated schemeID attribute. This setup works perfectly, and I’ve successfully retrieved and processed the data.
The issue arises with another example of the same CII format, where the field name is no longer GlobalID. Instead, it’s called ID, and the schemeID attribute is missing entirely. This variability in field names is causing parsing issues.
For some scenarios, I’ve managed to address similar problems by using the XMLConfig feature in XMLRecords to remap field names to match my structure. However, in this particular case, it seems that the issue lies in the nesting depth of the lists, and the remapping is not working as expected.
Has anyone encountered a similar issue? Is there another feature or method within the XMLRecords toolset or elsewhere that could help handle such variability in XML field names, especially for deeply nested structures? Any advice or suggestions would be greatly appreciated.I will attach the xml files and show some images of my structure.
Thank you!
My structure based of the CIIexample4xml provided:How the xml is on the first example I got:Now a different example provided:
Hello Diogo,
I believe that for this sort of polymorphic XML, you essentially have 3 realistic options:
- ask your XML source to normalize those fields: the most straightforward solution, not very practical depending on where you're pulling this data from and flattening these fields can cause extra complexity;
- normalize it yourself by preprocessing the XML and rewriting it into a more manageable form, whether by flattening the structure or by rewriting the tags into the values you've mapped to your OutSystems structure: less straightforward, but far more practical as you're in complete control, but can cause you issues down the road as you're essentially creating a secondary mapping on your end that may have to be updated and maintained down the road;
- create all possible variations of your polymorphic XML in one or more OutSystems structures: this would be the option I'd be inclined to take without having more information. Instead of trying to create aliases for your fields, directly create a new field called ram_ID in your ram_SellerTradeParty structure. XMLRecords will attempt to fill all existing fields of your structure, so in some cases you'll see values in the ram_ID field, and in others you'll see values in the ram_GlobalID structure.
When you're processing the XML with this last solution, you'll have to check each possible polymorphic field to see which one has the values you expect, and read from there. This can get messy fast depending on exactly how much polymorphism your XML has, but I believe that it's the solution that will cause less impact to your current architecture and logic.
Hello Afonso,
I ended up going with the third option as a workaround, though I was exploring whether there might be a way to achieve the same result via XML config within the XML Records that I might have missed.
I currently have logic to change the name of the field using XML config, but it only works at the first level of the structure. Is it not possible to apply it to deeper levels?For example:For Credit Note Invoices, the InvoiceLine is called CreditNoteLine. Since it is at the first level of the structure (directly after the Invoice list record), I can use XML config to rename the attribute to the correct one.
Regarding the first solution, it’s unfortunately beyond my control.The second solution is something I’ve seen implemented in other (non-OutSystems) projects. However, I’m concerned that it could make maintenance more challenging in the long term. Additionally, it’s not very straightforward to transform it into a standardized XML format.
Thank you again for sharing your insights. I really appreciate your help!
Dear @Diogo Fonseca .
Would you like to share your oml files?
Hello ndy,I just created a simple application using my structures and logic to convert the xmls.I will attach the OML.Thank you for your help.