Java Reference
In-Depth Information
ited with single quotes. XPath provides the = and != operators for comparing strings.
XPathalsopredefinesthe string() functiontoconvertitsargumenttoastring, con-
cat() to return a concatenation of its string arguments, starts-with() to return
true when the first argument string starts with the second argument string (and other-
wisereturnsfalse), contains() toreturntruewhenthefirstargumentstringcontains
thesecondargumentstring(andotherwisereturnsfalse), substring-before() to
returnthesubstringofthefirstargumentstringthatprecedesthefirstoccurrenceofthe
second argument string in the first argument string, or the empty string when the first
argumentstringdoesnotcontainthesecondargumentstring, substring-after()
toreturnthesubstringofthefirstargumentstringthatfollowsthefirstoccurrenceofthe
second argument string in the first argument string, or the empty string when the first
argumentstringdoesnotcontainthesecondargumentstring, substring() toreturn
thesubstringofthefirst(string)argumentstartingatthepositionspecifiedinthesecond
(number) argument with length specified in the third (number) argument, string-
length() toreturnthenumberofcharactersinitsstringargument(orthelengthofthe
contextnodewhenconvertedtoastringintheabsenceofanargument), normalize-
space() toreturntheargumentstringwithwhitespacenormalizedbystrippinglead-
ingandtrailingwhitespaceandreplacingsequencesofwhitespacecharactersbyasingle
space (or performing the same action on the context node when converted to a string
intheabsenceofanargument),and translate() toreturnthefirstargumentstring
withoccurrencesofcharactersinthesecondargumentstringreplacedbythecharacter
at the corresponding position in the third argument string.
Finally,XPathpredefinesseveralfunctionsforusewithnodesets: last() returnsa
numberidentifyingthelastnode, position() returnsanumberidentifyinganode's
position, count() returnsthenumberofnodesinitsnodesetargument, id() selects
elementsbytheiruniqueIDsandreturnsanodesetoftheseelements, local-name()
returns the local part of the qualified name of the first node in its nodeset argument,
namespace-uri() returnsthenamespacepartofthequalifiednameofthefirstnode
initsnodesetargument,and name() returnsthequalifiednameofthefirstnodeinits
nodeset argument.
XPath and DOM
Suppose you need someone in your home to purchase a bag of sugar. You can tell
thispersonto“Pleasebuymesomesugar.”Alternatively,youcouldsaythefollowing:
“Pleaseopenthefrontdoor.Walkdowntothesidewalk.Turnleft.Walkupthesidewalk
for three blocks. Turn right. Walk up the sidewalk one block. Enter the store. Go to
Search WWH ::




Custom Search