Skip to main content
Question

Dynamically constructing WFS XML query


redgeographics
Celebrity
Forum|alt.badge.img+50

I'm constructing an XML query for a WFS service by using an XMLTemplater. The ROOT element is this:

<Filter>
<Or>
{fme:process-features("SUB")}
</Or>
</Filter>

And the SUB element, per feature, is this

<PropertyIsEqualTo><PropertyName>identificatie</PropertyName><Literal>{fme:get-attribute("bag_vbo_id")}</Literal></PropertyIsEqualTo>

Store in an attribute then use that feature to trigger a FeatureReader and use the query attribute. This works fine and results in a working query. Except when there's only one feature, in that case the WFS service seems to bork about the unnecessary <Or> </Or> tags.

My workaround:

  1. StringSearcher to count the number of times </PropertyIsEqualTo> occurs (i.e. the number of sub elements)
  2. ListElementCounter on the list of matches
  3. TestFilter to test for the number of elements
  4. If 1 StringReplacer to replace the <Or> and </Or> with empty strings

I can't help but think there's got to be an easier way to do this... I could combine steps 3 and 4 in one conditional value, saving me one transformer, but it still amounts to the same thing really. Any other suggestions?

5 replies

itay
Supporter
Forum|alt.badge.img+17
  • Supporter
  • May 27, 2020

Hoi @redgeographics,

Would the BAG API be an option? I usually use that and not the WFS service.


redgeographics
Celebrity
Forum|alt.badge.img+50
itay wrote:

Hoi @redgeographics,

Would the BAG API be an option? I usually use that and not the WFS service.

I am actually using that later on in the process, it's certainly worth looking into but I'm not sure how well it will work when you need to query a few hundred features.

The irony is that the chance of my user ever querying just one feature is very small, but I can't have the workbench fail on that of course.


itay
Supporter
Forum|alt.badge.img+17
  • Supporter
  • May 28, 2020
redgeographics wrote:

I am actually using that later on in the process, it's certainly worth looking into but I'm not sure how well it will work when you need to query a few hundred features.

The irony is that the chance of my user ever querying just one feature is very small, but I can't have the workbench fail on that of course.

I don't see the problem with querying a couple of hundred records (just did that for a client with a few thousands queries)


ebygomm
Influencer
Forum|alt.badge.img+39
  • Influencer
  • May 28, 2020

Can you do something like in the root element?

<Filter>
{
let $sub :={
    fme:process-features("SUB")
}
return if (1 < fn:count($sub/Literal))
then <Or>{$sub}</Or>
else {$sub}
}
</Filter>

 

 


redgeographics
Celebrity
Forum|alt.badge.img+50
ebygomm wrote:

Can you do something like in the root element?

<Filter>
{
let $sub :={
    fme:process-features("SUB")
}
return if (1 < fn:count($sub/Literal))
then <Or>{$sub}</Or>
else {$sub}
}
</Filter>

 

 

Yes, that does the trick, thanks!


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