Skip to main content
Archived

Better and more consistent support for lists/collections (of one) when reading X

Related products:Integrations
  • rylanatsafe
    rylanatsafe
  • siennaatsafe
    siennaatsafe
  • davideagle
    davideagle
  • chriswilson
    chriswilson
  • mark_f

lifalin2016
Contributor

***Note from Migration:***

Original Title was: Better and more consistent support for lists/collections (of one) when reading XML


Hi,

I've just encountered a very irritating problem, that comes from FME handling lists/collections in an unexpected way (at least to me).

When I read an XML file, each item may have a collection of sub items, which may contain 0 or more items.

When FME reads the parent item, and finds sub items, it stores these in a list.

EXCEPT when there's just one sub item! Then the sub item attributes gets stored in non-list multi-level attributes.

This is inconsistent imho. If there are _any_ sub items present, a list should be always be generated. [MY SUGGESTION]

In the current scenario, I need three transformers to handle the case:

  1. Test whether the multi-level attributes exist (single sub item), or the list exists (multiple sub items).
  2. Rename the attributes if a single sub item is found.
  3. Explode the list if multiple sub items are found.

If the list was always generated if there are any sub items, I only need step 3.

The multi-level attributes could still be created, if a single sub item is encountered, to keep backward compatability.

Cheers

Lars I.

This post is closed to further activity.
It may be a question with a best answer, an implemented idea, or just a post needing no comment.
If you have a follow-up or related question, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

2 replies

lifalin2016
Contributor
Forum|alt.badge.img+29
  • Author
  • Contributor
  • November 18, 2016

Test workspace and data file.

 

test-xml-collection-of-one_1.fmw

jdh
Contributor
Forum|alt.badge.img+28
  • Contributor
  • November 18, 2016

I raise the same issue back in 2012. The response from Don was pretty much your workaround. To quote:

 

"The crux of the issue is that the XML reader is making its decisions based on the data that it is given. We have thought about this for awhile and will do more.

We made the decision that we didn’t want to turn everything into lists as we have found in XML as these are difficult to work with in FME.

What you can do with FME is when generating the workspace is to specify a whole bunch of XML files and then it will use all of that to figure out the various combinations of attributes. Then you can use attribute renamers to fix things up."

 

 

I for one would love to have single item lists treated as lists. Ie if the schema is defined as an array, then the element should be in a list, regardless of whether it's the only one or not.

 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings