Skip to main content
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="./at1a@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?

 

 

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.
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
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.
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.

 

 


Hi again,

 

 

have you looked at the XMLFlattener?

 

 

David

Reply