Solved

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


Badge +4

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

icon

Best answer by ebygomm 5 March 2021, 10:03

View original

3 replies

Userlevel 1
Badge +10

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

Userlevel 6
Badge +32

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 :)

Badge +4

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.

Reply