Skip to main content
Solved

XML values within tags to attributes


tomw202
Participant
Forum|alt.badge.img+4

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!

Best answer by erik_jan

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.

View original
Did this help you find an answer to your question?

2 replies

erik_jan
Contributor
Forum|alt.badge.img+18
  • Contributor
  • Best Answer
  • March 11, 2019

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.


tomw202
Participant
Forum|alt.badge.img+4
  • Author
  • Participant
  • March 13, 2019
erik_jan wrote:

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!


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