when to use != or not() in XPath

3
Simple question. When should I use not() and when should I use !=. Example: //General.User[active != true()] or //General.User[not(active = true())] Is there any technical difference between both solutions?
asked
4 answers
9

The difference between them is that "!=" compares two values and if they are the same it returns false, if not it returns true. "not()" checks whether certain logic holds true and if so it returns false, if not it returns true. In other words "not()" is a logical operator while "!=" is a comparison operator.

To quote some random page on the internet:
Comparison operators are used in logical statements to determine equality or difference between variables or values.
Logical operators are used to determine the logic between variables or values.

Say x = false and y = false:

not(x and y) returns true;
while x != y returns false;

EDIT (added): Compare: "not(x=100)" to "x!=100" and it should be obvious why using != is superior for comparing two values.

In your example I am not sure it matters, maybe there is a performance difference but for such a simple case it will be negligible. Even so, in your example I would use neither and opt for //General.User[active = false()] instead.

answered
6

If applicable, != should always be preferred above 'not()', because not tells the database to inverse a result set (in other words 'please provide me all rows that did not match the inner query) and '!=' just compares two values, which is way cheaper.

answered
2

See my answer to this question:

https://forum.mendix.com/questions/15/How-do-I-show-an-object-in-a-datagrid-that-has-no-association-to-another-object

answered
0

I would choose for readability.

Not can include several expressions and != is part of one expression as an operator.

answered