Java Reference
In-Depth Information
set,XPathconvertsthatnodesettotruewhenthenodesetisnonempty;otherwise,XPath
converts that nodeset to false.
Note
The previously presented location path expression examples demonstrate
XPath's abbreviated syntax. However, XPath also supports an unabbreviated syntax
thatismoredescriptiveofwhatishappeningandisbasedonan
axis specifier
,which
indicatesthenavigationdirectionwithintheXMLdocument'streerepresentation.For
example,where
/movie/name
selectsall
movie
childelementsoftherootnodefol-
lowedbyall
name
childelementsofthe
movie
elementsusingtheabbreviatedsyntax,
/child::movie/child::name
accomplishes the same task with the expanded
syntax.CheckoutWikipedia's“XPath1.0”entry(
http://en.wikipedia.org/
wiki/XPath_1.0
)
for more information.
Locationpathexpressions(whichreturnnodesets)areonekindofXPathexpressions.
XPath also supports
general expressions
that evaluate to Boolean (e.g., predicates),
number, or string type; for example,
position()=2
,
6.8
, and
"Hello"
. General
expressions are often used in XSLT.
XPathBooleanvaluescanbecomparedviarelationaloperators
<
,
<=
,
>
,
>=
,
=
,and
!=
.Booleanexpressionscanbecombinedbyusingoperators
and
and
or
.XPathpre-
defines the
boolean()
function to convert its argument to a string,
not()
to re-
turn true when its Boolean argument is false and vice versa,
true()
to return true,
false()
toreturnfalse,and
lang()
toreturntrueorfalsedependingonwhetherthe
languageofthecontextnode(asspecifiedby
xml:lang
attributes)isthesameasoris
a sublanguage of the language specified by the argument string.
XPath provides the
+
,
-
,
*
,
div
, and
mod
(remainder) operators for working with
numbers—forward slash cannot be used for division because this character is used to
separatelocationsteps.AllfiveoperatorsbehaveliketheirJavalanguagecounterparts.
XPath also predefines the
number()
function to convert its argument to a number,
sum()
toreturnthesumofthenumericvaluesrepresentedbythenodesinitsnodeset
argument,
floor()
toreturnthelargest(closesttopositiveinfinity)numberthatisnot
greaterthanitsnumberargumentandthatisaninteger,
ceiling()
toreturnthesmal-
lest (closest tonegative infinity) number that isnotless than its number argument and
thatisaninteger,and
round()
toreturnthenumberthatisclosesttotheargumentand
thatisaninteger.Whentherearetwosuchnumbers,theoneclosesttopositiveinfinity
is returned.
XPath strings are ordered character sequences that are enclosed in single quotes or
double quotes. A string literal cannot contain the same kind of quote that is also used
todelimitthestring.Forexample,astringthatcontainsasinglequotecannotbedelim-