tags:

views:

82

answers:

1

Hello,

i have this construct to questionate my xml-document with a binding in xaml.

XPath="/doc/B/lists/entry[@value=(/doc/A/selectedValue)]"

If the path /doc/A/selectedValue is empty or did not exist all nodes of /doc/B/list/entry are returned. Is there a way to define that nothing should be returned in the case that /doc/A/selectedValue is empty or did not exists?

Hope somebody can help,

Greetings Martin

+2  A: 

In theory, not all B entires are returned, but the only empty ones. When there is no selected value, /doc/A/selectedValue returns the empty node set. When compared against a string (@value), then the empty node-set is converted to the empty string. Which means that your expression will be equal to

/doc/B/lists/entry[@value='']

To avoid that, you simply need to make sure that /doc/A/selectedValue is not empty:

/doc/B/lists/entry[/doc/A/selectedValue != '' and @value=/doc/A/selectedValue]

Note that like any XPath, /doc/A/selectedValue can return multiple nodes. More explicit and defensive is /doc/A/selectedValue[1].

Tomalak
With several online-tests it works great, but in my XAML-Binding it always return the value of the content of the first path element.
martin
I found the problem was a strip of datawaste in my sourcecode.
martin