Skip to main content
Question

xfmap help

  • April 5, 2013
  • 5 replies
  • 87 views

jdh
Contributor
Forum|alt.badge.img+41
hi all,

 

 

I need to use the XMLFeatureMapper in a script, and I want to exclude nodes that contain a specific selfclosed tag.

 

 

if the xmls is

 

<feature>

 

<ID>1</ID>

 

</feature>

 

<feature>

 

<ID>2</ID>

 

<at1 name="a"/>

 

</feature>

 

<feature>

 

<ID>3</ID>

 

</feature>

 

 

I want to read in only feature 1 and 3, excluding all features with tag <at1 />.

 

 

I'm really not familiar with xfmap, but managed to get the following to read in all features:

 

 

<xfMap> <feature-map> <mapping match=feature">     <feature-type> <literal expr="feature"/> </feature-type>              <attributes> <attribute>                     <name>  <literal expr="ID"/> </name> <value> <extract expr="./ID"/>  </value> </attribute> <attribute>                     <name>  <literal expr="attribute1"/> </name> <value> <extract expr="./at1[@name]"/>  </value> </attribute> </attributes> </mapping> </feature-map>    </xfMap>

 

But i really want something to exclude the feature if it contains the tag, something like <mapping match="feature" except ="feature.at1"> but that is not the right syntax.

 

 

help?

 

 

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.

5 replies

fmelizard
Safer
Forum|alt.badge.img+22
  • Safer
  • April 5, 2013
Hi,

 

I would try to filter out the nodes before creating features, 

 

 that can be done with the xml fragmenter set to exclude or testing the fragments (tester/testfilter).

 

 Hope this helps.

david_r
Celebrity
  • April 6, 2013
Hi,

 

 

xfmaps can be hard to write. If you're using FME 2012 or newer, I strongly recommend to replace them with XML feature paths instead, they are a lot easier to work with.

 

 

Have a look at the following FMEpedia article on XML feature paths, it gives a lot of good info in how to get started.

 

 

For your example, I would just use a feature path on "feature" and then filter out the unwanted features using a Tester or something like that to isolate those with a particular attribute present.

 

 

David

fmelizard
Safer
Forum|alt.badge.img+22
  • Safer
  • April 8, 2013
Hi,

 

 

I agree with David, feature paths are a lot easier, see this short video, to get an idea how it works.

 

In your case after reading you can filter out the unnecessary nodes.

jdh
Contributor
Forum|alt.badge.img+41
  • Author
  • Contributor
  • April 8, 2013
So there were a couple of complications not mentioned, specifically I don't know what the xml path will be until I start processing another dataset, which will trigger the xml reading.  That leaves out anything involving an xml reader or FeatureReader transformer.

 

 

Also I don't actually know what the name/value pair in the self closing tag will be.  ie  <at1 name="a"/> i know that it will be <at1 something="something else"  optional="something optional" />

 

 

 

I did try the xml fragmenter instead of the xml feature mapper, but I couldn't  get the exclude to work properly.  It would excluded the attribute, but not the feature.  The xmlfragmenter also required that I manually expose the attributes I was interested in, and had a slightly  higher overhead in that it pulled in all the attributes from the xml file, not just the few I was interested in.  Going into the advanced flattening options seems just as complicated as producing an xfmap.

 

 


david_r
Celebrity
  • April 8, 2013
Hi again,

 

 

have you looked at the XMLFlattener?

 

 

David