Skip to main content
Question

Parsing XML properties properly

  • April 12, 2019
  • 1 reply
  • 16 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

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.

1 reply

takashi
Celebrity
  • 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