Data Types
Each XPath expression evaluates to one of four types:
- Boolean
A binary value that is either true or false. In XPath, Booleans are most commonly produced by using the comparison operators
=
,!=
,<
,>
,<=
, and>=
. Multiple conditions can be combined using theand
andor
operators, which have their usual meaning in logic (e.g.,3>2 or 2>1
is true). XPath does not offer Boolean literals. However, thetrue( )
andfalse()
functions fill that need.- Number
All numbers in XPath are IEEE 754-compliant, 64-bit floating-point numbers. This is the same as the
double
type in Java. Numbers range from 4.94065645841246544e-324d to 1.79769313486231570e+308d, and are either positive or negative. Numbers also include the special valuesInf
(positive infinity),-Inf
(negative infinity), andNaN
(not a number), which is used for the results of illegal operations, such as dividing by zero. XPath provides all the customary operators for working with numbers, including:+
Addition
-
Subtraction; however, this operator should always be surrounded by whitespace to avoid accidental misinterpretation as part of an XML name
*
Multiplication
div
Division
mod
Taking the remainder
- String
Sequence of zero or more Unicode characters. String literals are enclosed in either single or double quotes, as convenient. Unlike Java, XPath does not allow strings to be concatenated with the plus sign. However, the
concat( )
function serves this purpose.- Node-set
Collection of zero or more nodes from an XML document. Location ...
Get XML in a Nutshell, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.