Skip to main content
Solved

XML values within tags to attributes

  • March 11, 2019
  • 2 replies
  • 14 views

tomw202
Contributor
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.

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, 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

erik_jan
Contributor
Forum|alt.badge.img+22
  • Contributor
  • 2179 replies
  • 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
Contributor
Forum|alt.badge.img+4
  • Author
  • Contributor
  • 18 replies
  • March 13, 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.

Thanks @erik_jan thats exactly what I was after!