Solved

XML Elements as Attribute Names

  • 4 October 2018
  • 2 replies
  • 5 views

Badge

I have xml data (see attached). I'm trying to get the following result from this data:

ID= 9328

Buffer PH = 6.39

BS_CA = 68.2

and so on. I have no issues flattening the data, my problem is that the "buffer PH" for example needs to be an column with value of 6.39 as the data. But with the way the xml is set up the basic flattening gives me a feature for every <Data/> tag. I can use the transposer, but then I lose other info related to that sample. This particular xml only has one sample, but there can be multiple samples.

icon

Best answer by takashi 5 October 2018, 00:10

View original

2 replies

Userlevel 2
Badge +17

Hi @johnglick, a possible way is to use an XQuery expression to create desired attributes. Once you have extracted each "Sample" element as XML fragment with the XMLFragmenter (or using the "Elements as XML Fragments" parameter in the XMLFlattener and then the ListExploder), you can use the XMLXQueryExtractor to do that.

Example: xmlxquery-example.fmwt (FME 2018.1.0.2)

XQuery:

declare default element namespace "http://tempurl.org";for $d in //Result/Datareturn fme:set-attribute($d/@Element, data($d/Value))

Parameters: Assuming that "xml_fragment_Sample" stores a "Sample" element.

0684Q00000ArLMaQAN.png

Badge

Hi @johnglick, a possible way is to use an XQuery expression to create desired attributes. Once you have extracted each "Sample" element as XML fragment with the XMLFragmenter (or using the "Elements as XML Fragments" parameter in the XMLFlattener and then the ListExploder), you can use the XMLXQueryExtractor to do that.

Example: xmlxquery-example.fmwt (FME 2018.1.0.2)

XQuery:

declare default element namespace "http://tempurl.org";for $d in //Result/Datareturn fme:set-attribute($d/@Element, data($d/Value))

Parameters: Assuming that "xml_fragment_Sample" stores a "Sample" element.

0684Q00000ArLMaQAN.png

Thank-you very much.  Works perfectly!

 

 

Reply