How to use of XPath Operators in XML

In this article I will explain the operators of XPath.
  • 2395

Introduction

An XPath expression returns either a node-set, a string, a Boolean, or a number. Their are various number of operators that we used in XPath, the following shows some of the operators in XPath.

Operators, their Description with example and result.

  • + (Addition) :  + operator is used for addition, for example 10 + 40 returns the result as 50.

  • - (Subtraction) :  - operator is used for Subtraction, for example 40 - 10 returns the result as 30.

  • * (Multiplication) :  * operator is used for multiplication, for example 40 * 10 returns the result as 400.

  • div (Division) :  div operator is used for division, for example 40 div 10 returns the result as 4.

  • = (Equal) :  = operator is used for check the equality, for example salary=40000 returns true if salary is 40000 otherwise return false.

  • != (Not Equal) :  != operator is used for check the in-equality, for example salary!=40000 returns true if salary is not 40000 otherwise return false.

  • < (Less than) :  < operator is used for check the condition that whether the value is less than the next one or not, for example salary < 40000 returns true if salary is less than 40000 otherwise return false.

  • <= (Less than equal to)  :  <= operator is used for check the condition that whether the value is less than and equal to the next one or not, for example salary <= 40000 returns true if salary is less than and equal to 40000 otherwise return false.

  • > (Greater than)  :  > operator is used for check the condition that whether the value is greater than the next one or not, for example salary > 40000 returns true if salary is greater than 40000 otherwise return false.

  • >= (Greater than)  :  >= operator is used for check the condition that whether the value is greater than and equal to the next one or not, for example salary >= 40000 returns true if salary is greater than equal to 40000 otherwise return false.

  • or :  or operator is used to check two condition together, it return true if any one condition is true, for example salary=1000 or salary=4000 return true if salary is equal to 1000 and false if salary is 3000.

  • and :  and operator is again apply to two conditions like, salary<4000 and salary>40000 return true if salary is equals to 3000 and otherwise false.

  • mod (Modulus) :  mod operator is used to perform the modulus operation for example, 5 mod 2 returns 1.

  • |  :   It computes two node sets. for example , //employee | //trainee returns the node-sets of all the employee and trainee element.

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

 

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.