jaxp/src/java.xml/share/classes/javax/xml/xpath/package.html
author joehw
Tue, 27 Jan 2015 22:01:46 -0800
changeset 28695 427254b89b9e
parent 25868 686eef1e7a79
child 29999 8493f5fc1052
permissions -rw-r--r--
8054196: XPath: support any type Reviewed-by: alanb, lancea, dfuchs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
     1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
     2
<html>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
     3
<head>
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     4
<!--
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
     5
Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     6
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     7
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     8
This code is free software; you can redistribute it and/or modify it
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     9
under the terms of the GNU General Public License version 2 only, as
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    10
published by the Free Software Foundation.  Oracle designates this
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    11
particular file as subject to the "Classpath" exception as provided
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    12
by Oracle in the LICENSE file that accompanied this code.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    13
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    14
This code is distributed in the hope that it will be useful, but WITHOUT
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    15
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    16
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    17
version 2 for more details (a copy is included in the LICENSE file that
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    18
accompanied this code).
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    19
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    20
You should have received a copy of the GNU General Public License version
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    21
2 along with this work; if not, write to the Free Software Foundation,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    22
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    23
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    24
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    25
or visit www.oracle.com if you need additional information or have any
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    26
questions. 
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    27
-->
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    28
</head>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    29
<body bgcolor="white">
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    30
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    31
This package provides an <em>object-model neutral</em> API for the
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    32
evaluation of XPath expressions and access to the evaluation
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    33
environment.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    34
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    35
<p>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    36
The XPath API supports <a href="http://www.w3.org/TR/xpath">
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    37
    XML Path Language (XPath) Version 1.0</a>
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    38
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    39
<hr />
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    40
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    41
<ul>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    42
    <li><a href='#XPath.Overview'>1. XPath Overview</a></li>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    43
    <li><a href='#XPath.Expressions'>2. XPath Expressions</a></li>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    44
    <li><a href='#XPath.Datatypes'>3. XPath Data Types</a>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    45
        <ul>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    46
            <li><a href='#XPath.Datatypes.QName'>3.1 QName Types</a>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    47
            <li><a href='#XPath.Datatypes.Class'>3.2 Class Types</a>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    48
            <li><a href='#XPath.Datatypes.Enum'>3.3 Enum Types</a>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    49
        </ul>    
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    50
    </li>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    51
    <li><a href='#XPath.Context'>4. XPath Context</a></li>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    52
    <li><a href='#XPath.Use'>5. Using the XPath API</a></li>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    53
</ul>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    54
<p>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    55
<a name="XPath.Overview"></a>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    56
<h3>1. XPath Overview</h3>
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    57
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    58
<p>The XPath language provides a simple, concise syntax for selecting
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    59
nodes from an XML document. XPath also provides rules for converting a
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    60
node in an XML document object model (DOM) tree to a boolean, double,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    61
or string value. XPath is a W3C-defined language and an official W3C
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    62
recommendation; the W3C hosts the XML Path Language (XPath) Version
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    63
1.0 specification.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    64
</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    65
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    66
<p>XPath started in life in 1999 as a supplement to the XSLT and
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    67
XPointer languages, but has more recently become popular as a
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    68
stand-alone language, as a single XPath expression can be used to
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    69
replace many lines of DOM API code.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    70
</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    71
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    72
<a name="XPath.Expressions"></a>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    73
<h3>2. XPath Expressions</h3>
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    74
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    75
<p>An XPath <em>expression</em> is composed of a <em>location
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    76
path</em> and one or more optional <em>predicates</em>. Expressions
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    77
may also include XPath variables.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    78
</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    79
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    80
<p>The following is an example of a simple XPath expression:</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    81
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    82
<blockquote>
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    83
<pre>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    84
/foo/bar
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    85
</pre>
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    86
</blockquote>
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    87
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    88
<p>This example would select the <code>&lt;bar&gt;</code> element in
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    89
an XML document such as the following:</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    90
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    91
<blockquote>
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    92
<pre>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    93
&lt;foo&gt;
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    94
    &lt;bar/&gt;
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    95
&lt;/foo&gt;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    96
</pre>
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    97
</blockquote>
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    98
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    99
<p>The expression <code>/foo/bar</code> is an example of a location
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   100
path. While XPath location paths resemble Unix-style file system
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   101
paths, an important distinction is that XPath expressions return
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   102
<em>all</em> nodes that match the expression. Thus, all three
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   103
<code>&lt;bar&gt;</code> elements in the following document would be
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   104
selected by the <code>/foo/bar</code> expression:</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   105
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   106
<blockquote>
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   107
<pre>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   108
&lt;foo&gt;
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   109
    &lt;bar/&gt;
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   110
    &lt;bar/&gt;
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   111
    &lt;bar/&gt;
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   112
&lt;/foo&gt;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   113
</pre>
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   114
</blockquote>
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   115
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   116
<p>A special location path operator, <code>//</code>, selects nodes at
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   117
any depth in an XML document. The following example selects all
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   118
<code>&lt;bar&gt;</code> elements regardless of their location in a
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   119
document:</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   120
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   121
<blockquote>
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   122
<pre>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   123
//bar
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   124
</pre>
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   125
</blockquote>
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   126
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   127
<p>A wildcard operator, *, causes all element nodes to be selected.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   128
The following example selects all children elements of a
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   129
<code>&lt;foo&gt;</code> element:
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   130
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   131
<blockquote>
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   132
<pre>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   133
/foo/*
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   134
</pre>
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   135
</blockquote>
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   136
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   137
<p>In addition to element nodes, XPath location paths may also address
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   138
attribute nodes, text nodes, comment nodes, and processing instruction
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   139
nodes. The following table gives examples of location paths for each
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   140
of these node types:</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   141
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   142
<table border="1">
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   143
<tr>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   144
<td>Location Path</td>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   145
<td>Description</td>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   146
</tr>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   147
<tr>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   148
<td>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   149
<code>/foo/bar/<strong>@id</strong></code>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   150
</td>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   151
<td>Selects the attribute <code>id</code> of the <code>&lt;bar&gt;</code> element
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   152
</td>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   153
</tr>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   154
<tr>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   155
<td><code>/foo/bar/<strong>text()</strong></code>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   156
</td>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   157
<td>Selects the text nodes of the <code>&lt;bar&gt;</code> element. No
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   158
distinction is made between escaped and non-escaped character data.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   159
</td>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   160
</tr>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   161
<tr>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   162
<td><code>/foo/bar/<strong>comment()</strong></code>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   163
</td>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   164
<td>Selects all comment nodes contained in the <code>&lt;bar&gt;</code> element.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   165
</td>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   166
</tr>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   167
<tr>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   168
<td><code>/foo/bar/<strong>processing-instruction()</strong></code>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   169
</td>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   170
<td>Selects all processing-instruction nodes contained in the
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   171
<code>&lt;bar&gt;</code> element.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   172
</td>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   173
</tr>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   174
</table>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   175
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   176
<p>Predicates allow for refining the nodes selected by an XPath
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   177
location path. Predicates are of the form
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   178
<code>[<em>expression</em>]</code>. The following example selects all
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   179
<code>&lt;foo&gt;</code> elements that contain an <code>include</code>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   180
attribute with the value of <code>true</code>:</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   181
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   182
<blockquote>
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   183
<pre>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   184
//foo[@include='true']
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   185
</pre>
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   186
</blockquote>
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   187
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   188
<p>Predicates may be appended to each other to further refine an
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   189
expression, such as:</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   190
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   191
<blockquote>
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   192
<pre>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   193
//foo[@include='true'][@mode='bar']
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   194
</pre>
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   195
</blockquote>
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   196
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   197
<a name="XPath.Datatypes"></a>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   198
<h3>3. XPath Data Types</h3>
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   199
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   200
<p>While XPath expressions select nodes in the XML document, the XPath
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   201
API allows the selected nodes to be coalesced into one of the
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   202
following data types:</p>
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   203
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   204
<ul>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   205
<li><code>Boolean</code></li>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   206
<li><code>Number</code></li>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   207
<li><code>String</code></li>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   208
</ul>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   209
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   210
<a name="XPath.Datatypes.QName"></a>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   211
<h3>3.1 QName types</h3>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   212
The XPath API defines the following {@link javax.xml.namespace.QName} types to 
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   213
represent return types of an XPath evaluation:
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   214
<ul>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   215
<li>{@link javax.xml.xpath.XPathConstants#NODESET}</li>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   216
<li>{@link javax.xml.xpath.XPathConstants#NODE}</li>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   217
<li>{@link javax.xml.xpath.XPathConstants#STRING}</li>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   218
<li>{@link javax.xml.xpath.XPathConstants#BOOLEAN}</li>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   219
<li>{@link javax.xml.xpath.XPathConstants#NUMBER}</li>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   220
</ul>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   221
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   222
<p>The return type is specified by a {@link javax.xml.namespace.QName} parameter 
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   223
in method call used to evaluate the expression, which is either a call to
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   224
<code>XPathExpression.evalute(...)</code> or <code>XPath.evaluate(...)</code> 
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   225
methods. 
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   226
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   227
<p>When a <code>Boolean</code> return type is requested,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   228
<code>Boolean.TRUE</code> is returned if one or more nodes were
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   229
selected; otherwise, <code>Boolean.FALSE</code> is returned.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   230
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   231
<p>The <code>String</code> return type is a convenience for retrieving
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   232
the character data from a text node, attribute node, comment node, or
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   233
processing-instruction node. When used on an element node, the value
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   234
of the child text nodes is returned.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   235
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   236
<p>The <code>Number</code> return type attempts to coalesce the text
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   237
of a node to a <code>double</code> data type.
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   238
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   239
<a name="XPath.Datatypes.Class"></a>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   240
<h3>3.2 Class types</h3>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   241
In addition to the QName types, the XPath API supports the use of Class types
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   242
through the <code>XPathExpression.evaluteExpression(...)</code> or 
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   243
<code>XPath.evaluateExpression(...)</code> methods. 
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   244
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   245
The XPath data types are mapped to Class types as follows:
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   246
<ul>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   247
<li><code>Boolean</code> -- <code>Boolean.class</code></li>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   248
<li><code>Number</code> -- <code>Number.class</code></li>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   249
<li><code>String</code> -- <code>String.class</code></li>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   250
<li><code>Nodeset</code> -- <code>XPathNodes.class</code></li>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   251
<li><code>Node</code> -- <code>Node.class</code></li>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   252
</ul>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   253
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   254
<p>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   255
Of the subtypes of Number, only Double, Integer and Long are supported.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   256
         
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   257
<a name="XPath.Datatypes.Enum"></a>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   258
<h3>3.3 Enum types</h3>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   259
Enum types are defined in {@link javax.xml.xpath.XPathEvaluationResult.XPathResultType} 
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   260
that provide mappings between the QName and Class types above. The result of 
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   261
evaluating an expression using the <code>XPathExpression.evaluteExpression(...)</code> 
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   262
or <code>XPath.evaluateExpression(...)</code> methods will be of one of these types.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   263
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   264
<a name="XPath.Context"></a>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   265
<h3>4. XPath Context</h3>
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   266
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   267
<p>XPath location paths may be relative to a particular node in the
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   268
document, known as the <code>context</code>. A context consists of:
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   269
<ul>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   270
    <li>a node (the context node)</li>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   271
    <li>a pair of non-zero positive integers (the context position and the context size)</li>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   272
    <li>a set of variable bindings</li>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   273
    <li>a function library</li>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   274
    <li>the set of namespace declarations in scope for the expression</li>    
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   275
</ul>
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   276
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   277
<p>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   278
It is an XML document tree represented as a hierarchy of nodes, a 
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   279
{@link org.w3c.dom.Node} for example, in the JDK implementation.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   280
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   281
<a name="XPath.Use"></a>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   282
<h3>5. Using the XPath API</h3>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   283
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   284
Consider the following XML document:
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   285
<p>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   286
<blockquote>
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   287
<pre>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   288
&lt;widgets&gt;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   289
&lt;widget&gt;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   290
&lt;manufacturer/&gt;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   291
&lt;dimensions/&gt;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   292
&lt;/widget&gt;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   293
&lt;/widgets&gt;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   294
</pre>
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   295
</blockquote>
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   296
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   297
<p>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   298
The <code>&lt;widget&gt;</code> element can be selected with the following process:
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   299
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   300
<blockquote>
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   301
<pre>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   302
// parse the XML as a W3C Document
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   303
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   304
Document document = builder.parse(new File("/widgets.xml"));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   305
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   306
//Get an XPath object and evaluate the expression
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   307
XPath xpath = XPathFactory.newInstance().newXPath();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   308
String expression = "/widgets/widget";
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   309
Node widgetNode = (Node) xpath.evaluate(expression, document, XPathConstants.NODE);
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   310
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   311
//or using the evaluateExpression method
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   312
Node widgetNode = xpath.evaluateExpression(expression, document, Node.class);
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   313
</pre>
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   314
</blockquote>
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   315
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   316
<p>With a reference to the <code>&lt;widget&gt;</code> element, a
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   317
relative XPath expression can be written to select the
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   318
<code>&lt;manufacturer&gt;</code> child element:</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   319
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   320
<blockquote>
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   321
<pre>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   322
XPath xpath = XPathFactory.newInstance().newXPath();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   323
<strong>String expression = "manufacturer";</strong>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   324
Node manufacturerNode = (Node) xpath.evaluate(expression, <strong>widgetNode</strong>, XPathConstants.NODE);
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   325
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   326
//or using the evaluateExpression method
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   327
Node manufacturerNode = xpath.evaluateExpression(expression, <strong>widgetNode</strong>, Node.class);
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   328
</pre>
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   329
</blockquote>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   330
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   331
<p>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   332
In the above example, the XML file is read into a DOM Document before being passed
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   333
to the XPath API. The following code demonstrates the use of InputSource to 
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   334
leave it to the XPath implementation to process it:
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   335
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   336
<blockquote>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   337
<pre>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   338
XPath xpath = XPathFactory.newInstance().newXPath();
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   339
String expression = "/widgets/widget";
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   340
InputSource inputSource = new InputSource("widgets.xml");
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   341
NodeList nodes = (NodeList) xpath.evaluate(expression, inputSource, XPathConstants.NODESET);
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   342
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   343
//or using the evaluateExpression method
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   344
XPathNodes nodes = xpath.evaluate(expression, inputSource, XPathNodes.class);
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   345
</pre>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   346
</blockquote>
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   347
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   348
<p>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   349
In the above cases, the type of the expected results are known. In case where
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   350
the result type is unknown or any type, the {@link javax.xml.xpath.XPathEvaluationResult}
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   351
may be used to determine the return type. The following code demonstrates the usage:
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   352
<blockquote>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   353
<pre>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   354
XPathEvaluationResult&lt;?&gt; result = xpath.evaluateExpression(expression, document);
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   355
switch (result.type()) {
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   356
    case NODESET:
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   357
        XPathNodes nodes = (XPathNodes)result.value();
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   358
        ...
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   359
        break;
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   360
}
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   361
</pre>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   362
</blockquote>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   363
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   364
<p>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   365
The XPath 1.0 Number data type is defined as a double. However, the XPath 
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   366
specification also provides functions that returns Integer type. To facilitate
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   367
such operations, the XPath API allows Integer and Long to be used in 
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   368
{@code evaluateExpression} method such as the following code: 
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   369
<p>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   370
<blockquote>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   371
<pre>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   372
int count = xpath.evaluate("count(/widgets/widget)", document, Integer.class);
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   373
</pre>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   374
</blockquote>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   375
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   376
@since 1.5
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   377
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   378
</body>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   379
</html>