Solved

XML values within tags to attributes


Badge +3

Hi,

I have some XML formatted in the below way:

<?xml version="1.0" encoding="UTF-16"?>
<apple colour="red" shape="round">
  <attribute type="price" value="1"></attribute>
  <attribute type="source" value="supermarket"></attribute>
  <attribute type="bought" value="01/01/2019"></attribute>
</apple>
<apple colour="green" shape="round">
  <attribute type="price" value="0.75"></attribute>
  <attribute type="source" value="market"></attribute>
  <attribute type="bought" value="02/01/2019"></attribute>
</apple>

I need to get this into a flattened format, with one row per apple in this case, e.g:

 

colourshapepricesourceboughtredround1supermarket01/01/2019greenround0.75market02/01/2019

 

I've played around with the xml flattener and xfMaps, but can't quite get my head around how to access the data when the values are contained within the tags themselves.

Any help would be appreciated!

icon

Best answer by erik_jan 11 March 2019, 19:38

View original

2 replies

Userlevel 2
Badge +12

I had the same kind of challenge and found the ListKeyValuePairExtractor (a FME Hub transformer) very useful.

It allows you to define keys and values, where the key will become the attribute name and the value will be the new attributes value.

In your case the type will be the key and the value will be the value.

Hoe this helps.

Badge +3

I had the same kind of challenge and found the ListKeyValuePairExtractor (a FME Hub transformer) very useful.

It allows you to define keys and values, where the key will become the attribute name and the value will be the new attributes value.

In your case the type will be the key and the value will be the value.

Hoe this helps.

Thanks @erik_jan thats exactly what I was after!

Reply