Skip to main content
Solved

XML Elements as Attribute Names

  • October 4, 2018
  • 2 replies
  • 30 views

johnglick
Contributor
Forum|alt.badge.img+7

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

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.

2 replies

takashi
Celebrity
  • 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+7
  • Author
  • Contributor
  • October 5, 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

Thank-you very much.  Works perfectly!