Skip to main content
I am reading one XML file. An element can have zero or multiple occurences. When I am reading one XML there are multiple occurences and after flattening the element it is recognized as a list in FME. e.g. VectorScaleRange.CompositeTypeStyle.CompositeRule{}

 

 

However When I am reading another XML (based on same XSD), there is only one occurence and after flattening the element it is recognized as an attribute in FME. e.g. VectorScaleRange.CompositeTypeStyle.CompositeRule.LegendLabel (CompositeRule element again contains some other elements e.g. LegendLabel

 

 

In case the element is non-existent, I am using TestFilter to check the condition if the attribute is present or not. How to check if the element occurs multiple times in the XML. ListElementCounter is not working, since if there is only one occurence it is not showing up as a list.

 

 

I am trying to create a custom transformer which should be able to read all occurences of data. Kindly suggest an approach.

 

 

Regards,

 

Ananda
Hi,

 

 

the easiest solution is probably to use two Testers

 

 

VectorScaleRange.CompositeTypeStyle.CompositeRule -> If Exists

 

 

VectorScaleRange.CompositeTypeStyle.CompositeRule{0} -> If Exists

 

 

Based on those two tests it should be easy to determine a) if the attribute does not exist or b) it exists as a list, or c) it exists as a regular attribute.

 

 

You could incorporate this into a custom transformer to get something more flexible, if needed.

 

 

David
Hi,

 

 

An addition to David's suggestion is to use a testfilter incoorporating both tests into one transformer.

 

Hope this helps.
Can I use VectorScaleRange.CompositeTypeStyle.CompositeRule -> If Exists directly, because the CompositeRule again has sub-elements.

 

 

In a ListExploder, if the XML contains multiple CompositeRules, then the List Attribute shows VectorScaleRange.CompositeTypeStyle.CompositeRule{}. However, when there is only one CompositeRule, it is not present in the List Attribute.

 

 

Regards,

 

Ananda
Hi,

 

 

not sure I understand your question, but you are correct regarding the ListExploder:

 

  • ...CompositeRule{} is a list with one or more items
  • ...CompositeRule is NOT a list, just a regular attribute
The ListExploder only works on lists, as you correctly observe. But if you send all your objects (with or without this list) to the ListExploder, it will indicate which features has this list or not, depending on the output port.

 

 

David
In addition, if you have lists within lists, e.g. CompositeRule{}.Values{}, you will have to treat each list level separately. For the above example, this means first exploding CompositeRule{}, and for each of the exploded CompositeValue features you will also have to explode Values{} using a separate ListExploder.

 

 

Rather than exploding all the lists all the time, consider using a ListSearcher to skip directly to only those values that interest you, whenever possible

 

 

XML has gotten a lot easier in the latest versions of FME (notably 2012), but it can still be a chore to parse some of the more ornate schemas...

 

 

David

Reply