Skip to main content
Solved

XML Elements as Attribute Names


johnglick
Contributor
Forum|alt.badge.img+3

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.

Best answer by takashi

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

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

2 replies

takashi
Evangelist
  • Best Answer
  • October 4, 2018

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


johnglick
Contributor
Forum|alt.badge.img+3
  • Author
  • Contributor
  • October 5, 2018
takashi wrote:

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!

 

 


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