Skip to main content
Solved

How to extract (key,value) elements from multiple xlm files and turn them into a flat table?

  • March 5, 2021
  • 3 replies
  • 113 views

aguan
Supporter
Forum|alt.badge.img+11

I have multiple xml files, each with the same structure as shown below:

 <Metadata>

   <MDI key="MAXIMUM">9</MDI>

   <MDI key="MEAN">4.2018685725509</MDI>

   <MDI key="MINIMUM">0</MDI>

   <MDI key="STDDEV">2.3097856863945</MDI>

  </Metadata>

I want to create a table with using the MDI Keys as the column names, and the element values as the rows from all the xml files, as illustrated below. Can do a single file with AttributeTransposer, but could not figure out a simple way to load all the files together, feeling awkward with limited knowledge of FME XML transformers. Need some expert help here.

 Capture

Best answer by ebygomm

If you have a list of the filepaths, you can use an XMLXqueryExtractor, use the filepath as your XML input with XML Input set to XML File then 

for $m in //MDI
return fme:set-attribute($m/@key, $m/text())

Expose the MAXIMUM, MINIMUM,STDDEV & MEAN under the Attributes to Expose Parameter

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.

3 replies

ebygomm
Influencer
Forum|alt.badge.img+46
  • Influencer
  • Best Answer
  • March 5, 2021

If you have a list of the filepaths, you can use an XMLXqueryExtractor, use the filepath as your XML input with XML Input set to XML File then 

for $m in //MDI
return fme:set-attribute($m/@key, $m/text())

Expose the MAXIMUM, MINIMUM,STDDEV & MEAN under the Attributes to Expose Parameter


nielsgerrits
VIP
Forum|alt.badge.img+62

If you have a list of the filepaths, you can use an XMLXqueryExtractor, use the filepath as your XML input with XML Input set to XML File then 

for $m in //MDI
return fme:set-attribute($m/@key, $m/text())

Expose the MAXIMUM, MINIMUM,STDDEV & MEAN under the Attributes to Expose Parameter

Learned something new today :)


aguan
Supporter
Forum|alt.badge.img+11
  • Author
  • Supporter
  • March 6, 2021

If you have a list of the filepaths, you can use an XMLXqueryExtractor, use the filepath as your XML input with XML Input set to XML File then 

for $m in //MDI
return fme:set-attribute($m/@key, $m/text())

Expose the MAXIMUM, MINIMUM,STDDEV & MEAN under the Attributes to Expose Parameter

@ebygomm, brilliant, works like a charm. I wish I knew XQuery more. Thanks a bunch.