Skip to main content
Question

Parsing XML properties properly

  • April 12, 2019
  • 1 reply
  • 11 views

Hello - part 2 of an XML thread. 

 

I have a bunch of nodes in an XML document that look like this;

<nodes>
            <node>
              <properties>
                <property type="field_name">first_name</property>
                <property type="field_data">Ben</property>
              </properties>
            </node>
            <node>
              <properties>
                <property type="field_name">last_name</property>
                <property type="field_data">Potts</property>
              </properties>
            </node>
</nodes>

And I want to get those out as variables to use down the line in an FME workbench. At the moment I am relying on the order of them in a Test Filter (i.e. If @Value(_attr_name) = nodes.node{0}.properties.property{1} = first_name then put it on an output port of 'first_name') - however I hate relying on the order and I'm sure there is a better way of getting them out.

 

Any help would be much appreciated.

Ramo

1 reply

takashi
Influencer
  • April 12, 2019

If your goal is to extract two attributes called "first_name" with value "Ben" and "last_name" with value "Potts" from the XML document, the XMLXQueryExtractor might help you.

XQuery expression:

for $p in //properties
let $name := data($p/property[@type="field_name"])
let $value := data($p/property[@type="field_data"])
return fme:set-attribute($name$value)

0684Q00000ArKlmQAF.png

 


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