Skip to main content
Question

Dynamically constructing WFS XML query

  • May 27, 2020
  • 5 replies
  • 74 views

redgeographics
Celebrity
Forum|alt.badge.img+62

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?

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

itay
Supporter
Forum|alt.badge.img+18
  • 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+62

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+18
  • Supporter
  • May 28, 2020

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+46
  • 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+62

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!