Skip to main content
Solved

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


aguan
Contributor
Forum|alt.badge.img+11
  • Contributor

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

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

3 replies

ebygomm
Influencer
Forum|alt.badge.img+32
  • 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+54
ebygomm wrote:

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
Contributor
Forum|alt.badge.img+11
  • Author
  • Contributor
  • March 6, 2021
ebygomm wrote:

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.


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