XPath语法详解

  • XPath 示例

本主题回顾整个 XPath 参考中出现的语法示例。所有示例均基于本节后所附 《XPath 语法的示例 XML 文件》。

表达式 引用
./author

当前上下文中的所有  元素。注意,此表达式等效于下一行中的表达式。

author

当前上下文中的所有  元素。

first.name

当前上下文中的所有  元素。

/bookstore

本文档的文档元素 ( )。

//author

文档中的所有  元素。

book[/bookstore/@specialty = @style]

style 属性值等于文档根目录的  元素的 specialty 属性值的所有  元素。

author/first-name

属于  元素的子级的所有  元素。

bookstore//title

 元素中更深的一级或多级(任意子代)的所有 </tt> 元素。注意,此表达式不同于下一行中的表达式。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">bookstore/*/title</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 属于 <tt><bookstore></tt> 元素的孙级的所有 <tt><title></tt> 元素。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">bookstore//book/excerpt//emph</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> <tt><book></tt> 元素的 <tt><excerpt></tt> 子级中的任意位置和 <tt><bookstore></tt> 元素中的任意位置的所有 <tt><emph></tt> 元素。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">.//title</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 当前上下文中更深的一级或多级的所有 <tt><title></tt> 元素。注意,本质上只有这种情况需要句点表示法。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">author/*</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 属于 <tt><author></tt> 元素的子级的所有元素。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">book/*/last-name</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 属于 <tt><book></tt> 元素的孙级的所有 <tt><last-name></tt> 元素。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">*/*</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 当前上下文的所有孙级元素。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">*[@specialty]</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 具有 <tt>specialty</tt> 属性的所有元素。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">@style</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 当前上下文的 <tt>style</tt> 属性。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">price/@exchange</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 当前上下文中 <tt><price></tt> 元素的 <tt>exchange</tt> 属性。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">price/@exchange/total</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 返回空节点集,因为属性不包含元素子级。XML 路径语言 (XPath) 语法允许使用此表达式,但是严格意义上讲无效。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">book[@style]</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 当前上下文的具有 <tt>style</tt> 属性的所有 <tt><book></tt> 元素。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">book/@style</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 当前上下文的所有 <tt><book></tt> 元素的 <tt>style</tt> 属性。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">@*</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 当前元素上下文的所有属性。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">./first-name</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 当前上下文节点中的所有 <tt><first-name></tt> 元素。注意,此表达式等效于下一行中的表达式。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">first-name</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 当前上下文节点中的所有 <tt><first-name></tt> 元素。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">author[1]</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 当前上下文节点中的第一个 <tt><author></tt> 元素。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">author[first-name][3]</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 具有 <tt><first-name></tt> 子级的第三个 <tt><author></tt> 元素。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">my:book</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> <tt>my</tt> 命名空间中的 <tt><book></tt> 元素。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">my:*</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> <tt>my</tt> 命名空间中的所有元素。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">@my:*</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> <tt>my</tt> 命名空间中的所有属性(不包括 <tt>my</tt> 命名空间中的元素的未限定属性)。</p> </td> </tr> </tbody> </table> </div> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px">  </p> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 注意,索引相对于父级。考虑以下数据:</p> <div class="dp-highlighter" id="" style="font-family:Monaco,'DejaVu Sans Mono','Bitstream Vera Sans Mono',Consolas,'Courier New',monospace; font-size:12px; background-color:transparent; width:679px; overflow:auto; margin-left:9px; padding:1px; word-break:break-all; word-wrap:break-word"> <div class="bar"> <div class="tools" style="padding:3px; margin:0px; font-weight:bold"> Xml代码   <img class="star" src="http://img.e-com-net.com/image/info8/648bbd50cab7432a809ad154d3ba7374.jpg" alt="收藏代码" style="border:0px" width="0" height="0"> </div> </div> <ol start="1" class="dp-xml" style="font-size:1em; line-height:1.4em; margin:0px 0px 1px; padding:2px 0px; border:1px solid rgb(209,215,220); list-style-position:initial; color:rgb(43,145,175)"> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black"><span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">x</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">    <span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">y</span> <span class="tag" style="color:rgb(0,102,153); font-weight:bold">/></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">    <span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">y</span> <span class="tag" style="color:rgb(0,102,153); font-weight:bold">/></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black"><span class="tag" style="color:rgb(0,102,153); font-weight:bold"></</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">x</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black"><span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">x</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">    <span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">y</span> <span class="tag" style="color:rgb(0,102,153); font-weight:bold">/></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">    <span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">y</span> <span class="tag" style="color:rgb(0,102,153); font-weight:bold">/></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black"><span class="tag" style="color:rgb(0,102,153); font-weight:bold"></</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">x</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> </ol> </div>   <div class="tableSection"> 表达式 引用 <table width="100%" border="0"> <tbody> <tr></tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">x/y[1]</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 每个 <tt><x></tt> 的第一个 <tt><y></tt> 子级。此表达式等效于下一行中的表达式。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">x/y[position() = 1]</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 每个 <tt><x></tt> 的第一个 <tt><y></tt> 子级。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">(x/y)[1]</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> <tt><x></tt> 元素的整个 <tt><y></tt> 子级元素集中的第一个 <tt><y></tt> 。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">x[1]/y[2]</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 第一个 <tt><x></tt> 的第二个 <tt><y></tt> 子级。</p> </td> </tr> </tbody> </table> </div> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px">  </p> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 其他示例引用 《XPath 语法的示例 XML 文件》。</p> <div class="tableSection"> 表达式 引用 <table width="100%" border="0"> <tbody> <tr></tr> <tr> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> <tt>book[last()]</tt></p> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 当前上下文节点的最后一个 <tt><book></tt> 元素。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">book/author[last()]</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 当前上下文节点的每个 <tt><book></tt> 元素的最后一个 <tt><author></tt>子级。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">(book/author)[last()]</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 当前上下文节点的 <tt><book></tt> 元素的整个 <tt><author></tt> 子级元素集中的最后一个 <tt><author></tt> 元素。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">book[excerpt]</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 至少包含一个 <tt><excerpt></tt> 元素子级的所有 <tt><book></tt> 元素。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">book[excerpt]/title</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 属于 <tt><book></tt> 元素(也至少包含一个 <tt><excerpt></tt> 元素子级)的子级的所有 <tt><title></tt> 元素。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">book[excerpt]/author[degree]</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 至少包含一个 <tt><degree></tt> 元素子级并且属于 <tt><book></tt> 元素(也至少包含一个 <tt><excerpt></tt> 元素)子级的所有<tt><author></tt> 元素。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">book[author/degree]</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 所有包含 <tt><author></tt> 子级的 <tt><book></tt> 元素,该子级至少包含一个 <tt><degree></tt> 子级。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">author[degree][award]</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 至少包含一个 <tt><degree></tt> 元素子级以及至少包含一个<tt><award></tt> 元素子级的所有 <tt><author></tt> 元素。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">author[degree and award]</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 至少包含一个 <tt><degree></tt> 元素子级以及至少包含一个<tt><award></tt> 元素子级的所有 <tt><author></tt> 元素。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">author[(degree or award) and publication]</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 至少包含一个 <tt><degree></tt> 或 <tt><award></tt> 以及至少包含一个<tt><publication></tt> 子级的所有 <tt><author></tt> 元素。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">author[degree and not(publication)]</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 至少包含一个 <tt><degree></tt> 元素子级并且不包含<tt><publication></tt> 元素子级的所有 <tt><author></tt> 元素。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">author[not(degree or award) and publication]</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 至少包含一个 <tt><publication></tt> 元素子级并且不包含<tt><degree></tt> 和 <tt><award></tt> 元素子级的所有 <tt><author></tt> 元素。</p> </td> </tr> <tr> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> <tt>author[last-name = "Bob"]</tt></p> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 至少包含一个值为 <tt>Bob</tt> 的 <tt><last-name></tt> 元素子级的所有<tt><author></tt> 元素。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">author[last-name[1] = "Bob"]</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 第一个 <tt><last-name></tt> 子元素的值为 <tt>Bob</tt> 的所有 <tt><author></tt>元素。注意,此表达式等效于下一行中的表达式。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">author[last-name [position()=1]= "Bob"]</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 第一个 <tt><last-name></tt> 子元素的值为 <tt>Bob</tt> 的所有 <tt><author></tt>元素。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">degree[@from != "Harvard"]</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> <tt>from</tt> 属性不等于 <tt>"Harvard"</tt> 的所有 <tt><degree></tt> 元素。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">author[. = "Matthew Bob"]</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 所有值为 <tt>Matthew Bob</tt> 的 <tt><author></tt> 元素。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">author[last-name = "Bob" and ../price > 50]</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 包含值为 <tt>Bob</tt> 的 <tt><last-name></tt> 子元素以及值大于 50 的<tt><price></tt> 同辈元素的所有 <tt><author></tt> 元素。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">book[position() <= 3]</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 前三本书(1、2、3)。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">author[not(last-name = "Bob")]</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 不包含值为 <tt>Bob</tt> 的 <tt><last-name></tt> 子元素的所有 <tt><author></tt>元素。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">author[first-name = "Bob"]</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 至少包含一个值为 <tt>Bob</tt> 的 <tt><first-name></tt> 元素的所有<tt><author></tt> 元素。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">author[* = "Bob"]</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 所有包含任何值为 <tt>Bob</tt> 的子元素的 author 元素。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">author[last-name = "Bob" and first-name = "Joe"]</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 所有包含值为 <tt>Bob</tt> 的 <tt><last-name></tt> 子元素和值为 <tt>Joe</tt> 的<tt><first-name></tt> 子元素的 <tt><author></tt> 元素。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">price[@intl = "Canada"]</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 上下文节点中所有 <tt>intl</tt> 属性等于 <tt>"Canada"</tt> 的 <tt><price></tt> 元素。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">degree[position() < 3]</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 属于上下文节点子级的前两个 <tt><degree></tt> 元素。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">p/text()[2]</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 上下文节点中每个 <tt><p></tt> 元素的第二个文本节点。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">ancestor::book[1]</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 与上下文节点最接近的 <tt><book></tt> 上级。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">ancestor::book[author][1]</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 与上下文节点最接近的 <tt><book></tt> 上级,并且此 <tt><book></tt> 元素包含 <tt><author></tt> 元素子级。</p> </td> </tr> <tr> <td style="font-size:1em"> <div class="libCScode"> <div style="background-color:rgb(221,221,221)"> <pre class="libCScode" style="font-size:1em">ancestor::author[parent::book][1]</pre> </div> </div> </td> <td style="font-size:1em"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px"> 当前上下文中最接近的 <tt><author></tt> 上级,并且此 <tt><author></tt>元素是 <tt><book></tt> 元素的子级。</p> </td> </tr> </tbody> </table> </div> </div> </div> <p></p> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Helvetica,Tahoma,Arial,sans-serif; font-size:14px; line-height:25.1875px">  </p> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Helvetica,Tahoma,Arial,sans-serif; font-size:14px; line-height:25.1875px">  </p> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Helvetica,Tahoma,Arial,sans-serif; font-size:14px; line-height:25.1875px"> <strong><span style="font-size:14px">附:</span> </strong>《XPath 语法的示例 XML 文件》</p> <div class="dp-highlighter" id="" style="font-family:Monaco,'DejaVu Sans Mono','Bitstream Vera Sans Mono',Consolas,'Courier New',monospace; width:679px; overflow:auto; margin-left:9px; padding:1px; word-break:break-all; word-wrap:break-word; line-height:25.1875px"> <div class="bar"> <div class="tools" style="padding:3px; margin:0px; font-weight:bold"> Xml代码   <img class="star" src="http://img.e-com-net.com/image/info8/648bbd50cab7432a809ad154d3ba7374.jpg" alt="收藏代码" style="border:0px" width="0" height="0"> </div> </div> <ol start="1" class="dp-xml" style="font-size:1em; line-height:1.4em; margin:0px 0px 1px; padding:2px 0px; border:1px solid rgb(209,215,220); list-style-position:initial; color:rgb(43,145,175)"> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black"><span class="tag" style="color:rgb(0,102,153); font-weight:bold"><?</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">xml</span> <span class="attribute" style="color:red">version</span>=<span class="attribute-value" style="color:blue">"1.0"</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">?></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black"><span class="tag" style="color:rgb(0,102,153); font-weight:bold"><?</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">xml-stylesheet</span> <span class="attribute" style="color:red">type</span>=<span class="attribute-value" style="color:blue">"text/xsl"</span> <span class="attribute" style="color:red">href</span>=<span class="attribute-value" style="color:blue">"myfile.xsl"</span> <span class="tag" style="color:rgb(0,102,153); font-weight:bold">?></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black"><span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">bookstore</span> <span class="attribute" style="color:red">specialty</span>=<span class="attribute-value" style="color:blue">"novel"</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">    <span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">book</span> <span class="attribute" style="color:red">style</span>=<span class="attribute-value" style="color:blue">"autobiography"</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">        <span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">author</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">            <span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">first-name</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>Joe<span class="tag" style="color:rgb(0,102,153); font-weight:bold"></</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">first-name</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">            <span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">last-name</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>Bob<span class="tag" style="color:rgb(0,102,153); font-weight:bold"></</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">last-name</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">            <span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">award</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>Trenton Literary Review Honorable Mention<span class="tag" style="color:rgb(0,102,153); font-weight:bold"></</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">award</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">        <span class="tag" style="color:rgb(0,102,153); font-weight:bold"></</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">author</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">        <span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">price</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>12<span class="tag" style="color:rgb(0,102,153); font-weight:bold"></</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">price</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">    <span class="tag" style="color:rgb(0,102,153); font-weight:bold"></</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">book</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">    <span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">book</span> <span class="attribute" style="color:red">style</span>=<span class="attribute-value" style="color:blue">"textbook"</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">        <span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">author</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">            <span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">first-name</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>Mary<span class="tag" style="color:rgb(0,102,153); font-weight:bold"></</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">first-name</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">            <span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">last-name</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>Bob<span class="tag" style="color:rgb(0,102,153); font-weight:bold"></</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">last-name</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">            <span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">publication</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">                Selected Short Stories of  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">                <span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">first-name</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>Mary<span class="tag" style="color:rgb(0,102,153); font-weight:bold"></</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">first-name</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">                <span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">last-name</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>Bob<span class="tag" style="color:rgb(0,102,153); font-weight:bold"></</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">last-name</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">            <span class="tag" style="color:rgb(0,102,153); font-weight:bold"></</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">publication</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">        <span class="tag" style="color:rgb(0,102,153); font-weight:bold"></</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">author</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">        <span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">editor</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">            <span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">first-name</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>Britney<span class="tag" style="color:rgb(0,102,153); font-weight:bold"></</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">first-name</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">            <span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">last-name</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>Bob<span class="tag" style="color:rgb(0,102,153); font-weight:bold"></</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">last-name</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">        <span class="tag" style="color:rgb(0,102,153); font-weight:bold"></</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">editor</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">        <span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">price</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>55<span class="tag" style="color:rgb(0,102,153); font-weight:bold"></</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">price</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">    <span class="tag" style="color:rgb(0,102,153); font-weight:bold"></</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">book</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">    <span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">magazine</span> <span class="attribute" style="color:red">style</span>=<span class="attribute-value" style="color:blue">"glossy"</span> <span class="attribute" style="color:red">frequency</span>=<span class="attribute-value" style="color:blue">"monthly"</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">        <span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">price</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>2.50<span class="tag" style="color:rgb(0,102,153); font-weight:bold"></</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">price</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">        <span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">subscription</span> <span class="attribute" style="color:red">price</span>=<span class="attribute-value" style="color:blue">"24"</span> <span class="attribute" style="color:red">per</span>=<span class="attribute-value" style="color:blue">"year"</span> <span class="tag" style="color:rgb(0,102,153); font-weight:bold">/></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">    <span class="tag" style="color:rgb(0,102,153); font-weight:bold"></</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">magazine</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">    <span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">book</span> <span class="attribute" style="color:red">style</span>=<span class="attribute-value" style="color:blue">"novel"</span> <span class="attribute" style="color:red">id</span>=<span class="attribute-value" style="color:blue">"myfave"</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">        <span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">author</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">            <span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">first-name</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>Toni<span class="tag" style="color:rgb(0,102,153); font-weight:bold"></</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">first-name</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">            <span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">last-name</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>Bob<span class="tag" style="color:rgb(0,102,153); font-weight:bold"></</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">last-name</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">            <span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">degree</span> <span class="attribute" style="color:red">from</span>=<span class="attribute-value" style="color:blue">"Trenton U"</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>B.A.<span class="tag" style="color:rgb(0,102,153); font-weight:bold"></</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">degree</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">            <span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">degree</span> <span class="attribute" style="color:red">from</span>=<span class="attribute-value" style="color:blue">"Harvard"</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>Ph.D.<span class="tag" style="color:rgb(0,102,153); font-weight:bold"></</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">degree</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">            <span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">award</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>Pulitzer<span class="tag" style="color:rgb(0,102,153); font-weight:bold"></</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">award</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">            <span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">publication</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>Still in Trenton<span class="tag" style="color:rgb(0,102,153); font-weight:bold"></</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">publication</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">            <span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">publication</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>Trenton Forever<span class="tag" style="color:rgb(0,102,153); font-weight:bold"></</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">publication</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">        <span class="tag" style="color:rgb(0,102,153); font-weight:bold"></</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">author</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">        <span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">price</span> <span class="attribute" style="color:red">intl</span>=<span class="attribute-value" style="color:blue">"Canada"</span> <span class="attribute" style="color:red">exchange</span>=<span class="attribute-value" style="color:blue">"0.7"</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>6.50<span class="tag" style="color:rgb(0,102,153); font-weight:bold"></</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">price</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">        <span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">excerpt</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">            <span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">p</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>It was a dark and stormy night.<span class="tag" style="color:rgb(0,102,153); font-weight:bold"></</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">p</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">            <span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">p</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">                But then all nights in Trenton seem dark and stormy to  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">                someone who has gone through what  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">                <span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">emph</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>I<span class="tag" style="color:rgb(0,102,153); font-weight:bold"></</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">emph</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">                have.  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">            <span class="tag" style="color:rgb(0,102,153); font-weight:bold"></</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">p</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">            <span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">definition-list</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">                <span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">term</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>Trenton<span class="tag" style="color:rgb(0,102,153); font-weight:bold"></</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">term</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">                <span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">definition</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>misery<span class="tag" style="color:rgb(0,102,153); font-weight:bold"></</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">definition</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">            <span class="tag" style="color:rgb(0,102,153); font-weight:bold"></</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">definition-list</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">        <span class="tag" style="color:rgb(0,102,153); font-weight:bold"></</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">excerpt</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">    <span class="tag" style="color:rgb(0,102,153); font-weight:bold"></</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">book</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">    <span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">my:book</span> <span class="attribute" style="color:red">xmlns:my</span>=<span class="attribute-value" style="color:blue">"uri:mynamespace"</span> <span class="attribute" style="color:red">style</span>=<span class="attribute-value" style="color:blue">"leather"</span> <span class="attribute" style="color:red">price</span>=<span class="attribute-value" style="color:blue">"29.50"</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">        <span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">my:title</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>Who's Who in Trenton<span class="tag" style="color:rgb(0,102,153); font-weight:bold"></</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">my:title</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">        <span class="tag" style="color:rgb(0,102,153); font-weight:bold"><</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">my:author</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>Robert Bob<span class="tag" style="color:rgb(0,102,153); font-weight:bold"></</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">my:author</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black">    <span class="tag" style="color:rgb(0,102,153); font-weight:bold"></</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">my:book</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> <li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px"> <span style="color:black"><span class="tag" style="color:rgb(0,102,153); font-weight:bold"></</span><span class="tag-name" style="color:rgb(0,102,153); font-weight:bold">bookstore</span><span class="tag" style="color:rgb(0,102,153); font-weight:bold">></span>  </span></li> </ol> </div> <p><br> </p> <p>引自 http://jiangzhengjun.iteye.com/blog/483048</p> <p><br> </p> <p><br> </p> <p></p> <div id="intro" style="margin:0px 0px 0px 15px; padding:20px 0px; border-width:1px 0px; border-top-style:solid; border-bottom-style:solid; border-top-color:rgb(170,170,170); border-bottom-color:rgb(170,170,170); width:710px; font-family:Verdana,Arial,宋体; background-color:rgb(249,249,249)"> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; border:0px; line-height:18px"> <span style="margin:0px; padding:0px; border:0px; font-family:微软雅黑; font-size:14px; font-weight:800">XPath 使用路径表达式来选取 XML 文档中的节点或节点集。节点是通过沿着路径 (path) 或者步 (steps) 来选取的。</span></p> </div> <div style="margin:0px 0px 0px 15px; padding:20px 0px; border-width:1px 0px; border-top-style:solid; border-bottom-style:solid; border-top-color:rgb(170,170,170); border-bottom-color:rgb(170,170,170); width:710px; font-family:Verdana,Arial,宋体; background-color:rgb(249,249,249)"> <h2 style="margin:0px; padding:0px; border:0px; font-family:微软雅黑; font-size:14px"> XML 实例文档</h2> <p style="margin-top:12px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; border:0px; line-height:18px"> 我们将在下面的例子中使用这个 XML 文档。</p> <pre style="margin-top:10px; margin-bottom:0px; padding:10px; border:1px dotted rgb(119,136,85); font-family:'Courier New',Courier,monospace; width:650px; background-color:rgb(245,245,245)"><?xml version="1.0" encoding="ISO-8859-1"?> <bookstore> <book> <title lang="eng">Harry Potter 29.99 Learning XML 39.95

选取节点

XPath 使用路径表达式在 XML 文档中选取节点。节点是通过沿着路径或者 step 来选取的。

下面列出了最有用的路径表达式:

表达式 描述
nodename 选取此节点的所有子节点。
/ 从根节点选取。
// 从匹配选择的当前节点选择文档中的节点,而不考虑它们的位置。
. 选取当前节点。
.. 选取当前节点的父节点。
@ 选取属性。

实例

在下面的表格中,我们已列出了一些路径表达式以及表达式的结果:

路径表达式 结果
bookstore 选取 bookstore 元素的所有子节点。
/bookstore

选取根元素 bookstore。

注释:假如路径起始于正斜杠( / ),则此路径始终代表到某元素的绝对路径!

bookstore/book 选取属于 bookstore 的子元素的所有 book 元素。
//book 选取所有 book 子元素,而不管它们在文档中的位置。
bookstore//book 选择属于 bookstore 元素的后代的所有 book 元素,而不管它们位于 bookstore 之下的什么位置。
//@lang 选取名为 lang 的所有属性。

谓语(Predicates)

谓语用来查找某个特定的节点或者包含某个指定的值的节点。

谓语被嵌在方括号中。

实例

在下面的表格中,我们列出了带有谓语的一些路径表达式,以及表达式的结果:

路径表达式 结果
/bookstore/book[1] 选取属于 bookstore 子元素的第一个 book 元素。
/bookstore/book[last()] 选取属于 bookstore 子元素的最后一个 book 元素。
/bookstore/book[last()-1] 选取属于 bookstore 子元素的倒数第二个 book 元素。
/bookstore/book[position()<3] 选取最前面的两个属于 bookstore 元素的子元素的 book 元素。
//title[@lang] 选取所有拥有名为 lang 的属性的 title 元素。
//title[@lang='eng'] 选取所有 title 元素,且这些元素拥有值为 eng 的 lang 属性。
/bookstore/book[price>35.00] 选取 bookstore 元素的所有 book 元素,且其中的 price 元素的值须大于 35.00。
/bookstore/book[price>35.00]/title 选取 bookstore 元素中的 book 元素的所有 title 元素,且其中的 price 元素的值须大于 35.00。

选取未知节点

XPath 通配符可用来选取未知的 XML 元素。

通配符 描述
* 匹配任何元素节点。
@* 匹配任何属性节点。
node() 匹配任何类型的节点。

实例

在下面的表格中,我们列出了一些路径表达式,以及这些表达式的结果:

路径表达式 结果
/bookstore/* 选取 bookstore 元素的所有子元素。
//* 选取文档中的所有元素。
//title[@*] 选取所有带有属性的 title 元素。

选取若干路径

通过在路径表达式中使用“|”运算符,您可以选取若干个路径。

实例

在下面的表格中,我们列出了一些路径表达式,以及这些表达式的结果:

路径表达式 结果
//book/title | //book/price 选取 book 元素的所有 title 和 price 元素。
//title | //price 选取文档中的所有 title 和 price 元素。
/bookstore/book/title | //price 选取属于 bookstore 元素的 book 元素的所有 title 元素,以及文档中所有的 price 元素。


引自 http://www.w3school.com.cn/xpath/xpath_syntax.asp



XPath 表达式的上下文

.NET Framework 4.5
其他版本
此主题尚未评级 评价此主题

XPath 表达式的计算取决于运算表达式所针对的上下文。 上下文包括计算表达式所针对的节点及其关联的环境,包括下列内容:

  • 上下文节点相对于同辈节点的位置(按文档顺序)。

  • 上下文的大小 — 即上下文节点的同辈节点数加 1。

  • 可以解析变量引用的变量绑定。

  • 函数库。

  • 表达式范围中的命名空间声明。

为了更好地评价上下文的概念,请考虑包含节点的树。 向树根请求所有名为 X 的节点时,将返回一个结果集,而向树枝请求这些节点时,将返回不同的结果集。 因此,表达式的结果取决于执行表达式所针对的上下文。

XPath 表达式可以在一个特定的上下文匹配特定的模式,返回结果,然后相对于所返回节点的上下文执行其他运算。 这样,在整个文档树中进行搜索时,使用 XPath 表达式非常灵活。

基本 XPath 表达式

以下是基本的 XPath 表达式类型。 每一类型都在下面进行了描述。

  • 当前上下文

  • 文档根

  • 根元素

  • 递归下降

  • 特定元素

示例

下面的示例显示一些基本的 XPath 表达式。 通过将这些简单的表达式组合在一起,并使用各种 XPath 运算符和特殊字符,可以生成更复杂的表达式。

当前上下文

以句点和正斜杠 (./) 作为前缀的表达式明确使用当前上下文作为上下文。 例如,下面的表达式引用当前上下文内的所有  元素:

./author

注意,此表达式等效于以下表达式:

author
文档根

以正斜杠 (/) 为前缀的表达式使用文档树的根作为上下文。 例如,下面的表达式引用此文档根处的  元素:

/bookstore
根元素

使用正斜杠后接星号 (/*) 的表达式将使用根元素作为上下文。 例如,以下表达式查找文档的根元素:

/*
递归下降

使用双正斜杠 (//) 的表达式指示可以包括零个或多个层次结构级别的搜索。 如果此运算符出现在模式的开头,上下文相对于文档的根。 例如,下面的表达式引用当前文档内任何位置的所有  元素:

//author

.// 前缀指示上下文从层次结构中当前上下文所指示的级别开始。

特定元素

以元素名开头的表达式引用特定元素的查询,从当前上下文节点开始。 例如,下面的表达式引用当前上下文节点中  元素内的  元素:

images/background.jpg

下面的表达式引用当前上下文节点中  元素内  元素的集合。

bookstore/book

下面的表达式引用当前上下文节点中所有的  元素:

first.name
注意

元素名可以包括句点字符 (.)。这些名称的用法与任何其他名称一样。


运算符和特殊字符

.NET Framework 4.5
其他版本
1(共 1)对本文的评价是有帮助 评价此主题

XPath 表达式是使用下表中所示的运算符和特殊字符构造的。

/

子运算符;选择左侧集合的直接子级。 此路径运算符出现在模式开头时,表示应从根节点选择该子级。

//

递归下降;在任意深度搜索指定元素。 此路径运算符出现在模式开头时,表示应从根节点递归下降。

.

指示当前上下文。

..

当前上下文节点的父级。

*

通配符;选择所有元素,与元素名无关。

@

属性;属性名的前缀。

@*

属性通配符;选择所有属性,与名称无关。

:

命名空间分隔符;将命名空间前缀与元素名或属性名分隔。

( )

为运算分组,明确设置优先级。

[ ]

应用筛选模式。

[ ]

下标运算符;用于在集合中编制索引。

+

执行加法。

-

执行减法。

div

根据 IEEE 754 执行浮点除法。

*

执行乘法。

mod

从截断除法返回余数。

此表不包括布尔运算符和集运算符,这两个运算符在布尔、比较和集表达式或集运算中列出。

优先级顺序(从最高优先级到最低优先级)的定义如下表所示。

优先级

字符

用途

1

( )

分组

2

[ ]

筛选器

3

/ //

路径运算

分组运算符 () 仅适用于顶级路径表达式。 例如,(//author/degree | //author/name) 是有效的分组运算,但 //author/(degree | name) 不是。

筛选模式运算符 ([]) 的优先级高于路径运算符(/ 和 //)。 例如,表达式 //comment()[3] 选择相对于文档中任意位置备注的父级索引等于 3 的所有备注。 此表达式与表达式(//comment())[3] 不同,后者选择相对于父级的所有备注集中的第三个备注。 前一个表达式可以返回多个备注,后一个表达式只能返回一个备注。

这些运算符和特殊字符在本参考文档中详细说明。

路径运算符

特定类型的元素集合可以使用路径运算符(/ 和 //)确定。 这些运算符根据其参数的“左侧”集合进行选择,“右侧”集合表示要选择的元素。 子运算符 (/) 从左侧集合的直接子级中选择,而子代运算符 (//) 从左侧集合的任意子代中选择。 因此,// 可以作为一个或多个层次结构级别的替代。

注意,路径运算符在执行查询时更改上下文。 通过将路径运算符连接在一起,用户可以遍历文档树。

示例

表达式

引用

author/first-name

当前上下文节点的  元素中的所有  元素。

bookstore//title

 元素中一级或多级深度的所有 </span> 元素(任意后代)。 </span><span id="mt48" class="sentence">注意,此表达式与以下模式 <span class="code" style="font-family:Consolas,Courier,monospace; color:rgb(0,100,0)">bookstore/*/title</span> 不同。</span></p> </td> </tr> <tr> <td style="font-family:'Microsoft YaHei UI','Microsoft YaHei',SimSun,'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif!important; border:1px solid rgb(187,187,187); margin:10px; padding:10px 8px; color:rgb(42,42,42); vertical-align:top"> <p style="margin-top:0px; margin-bottom:0px; padding-bottom:0px; line-height:18px"> <span class="code" style="font-family:Consolas,Courier,monospace; color:rgb(0,100,0)">bookstore/*/title</span></p> </td> <td style="font-family:'Microsoft YaHei UI','Microsoft YaHei',SimSun,'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif!important; border:1px solid rgb(187,187,187); margin:10px; padding:10px 8px; color:rgb(42,42,42); vertical-align:top"> <p style="margin-top:0px; margin-bottom:0px; padding-bottom:0px; line-height:18px"> <span id="mt49" class="sentence">作为 <span class="code" style="font-family:Consolas,Courier,monospace; color:rgb(0,100,0)"><bookstore></span> 元素的孙代的所有 <span class="code" style="font-family:Consolas,Courier,monospace; color:rgb(0,100,0)"><title></span> 元素。</span></p> </td> </tr> <tr> <td style="font-family:'Microsoft YaHei UI','Microsoft YaHei',SimSun,'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif!important; border:1px solid rgb(187,187,187); margin:10px; padding:10px 8px; color:rgb(42,42,42); vertical-align:top"> <p style="margin-top:0px; margin-bottom:0px; padding-bottom:0px; line-height:18px"> <span class="code" style="font-family:Consolas,Courier,monospace; color:rgb(0,100,0)">bookstore//book/excerpt//emph</span></p> </td> <td style="font-family:'Microsoft YaHei UI','Microsoft YaHei',SimSun,'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif!important; border:1px solid rgb(187,187,187); margin:10px; padding:10px 8px; color:rgb(42,42,42); vertical-align:top"> <p style="margin-top:0px; margin-bottom:0px; padding-bottom:0px; line-height:18px"> <span id="mt50" class="sentence"><span class="code" style="font-family:Consolas,Courier,monospace; color:rgb(0,100,0)"><book></span> 元素的 <span class="code" style="font-family:Consolas,Courier,monospace; color:rgb(0,100,0)"><excerpt></span> 子级中的任意位置和 <span class="code" style="font-family:Consolas,Courier,monospace; color:rgb(0,100,0)"><bookstore></span> 元素中的任意位置的所有 <span class="code" style="font-family:Consolas,Courier,monospace; color:rgb(0,100,0)"><emph></span> 元素:</span></p> </td> </tr> <tr> <td style="font-family:'Microsoft YaHei UI','Microsoft YaHei',SimSun,'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif!important; border:1px solid rgb(187,187,187); margin:10px; padding:10px 8px; color:rgb(42,42,42); vertical-align:top"> <p style="margin-top:0px; margin-bottom:0px; padding-bottom:0px; line-height:18px"> <span class="code" style="font-family:Consolas,Courier,monospace; color:rgb(0,100,0)">.//title</span></p> </td> <td style="font-family:'Microsoft YaHei UI','Microsoft YaHei',SimSun,'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif!important; border:1px solid rgb(187,187,187); margin:10px; padding:10px 8px; color:rgb(42,42,42); vertical-align:top"> <p style="margin-top:0px; margin-bottom:0px; padding-bottom:0px; line-height:18px"> <span id="mt51" class="sentence">当前上下文中一级或多级深度的所有 <span class="code" style="font-family:Consolas,Courier,monospace; color:rgb(0,100,0)"><title></span> 元素。 </span><span id="mt52" class="sentence">注意,本质上只有这种情况需要句点表示法。</span></p> </td> </tr> </tbody> </table> </div> </div> </div> <div> <div class="LW_CollapsibleArea_TitleDiv" style="font-family:'Segoe UI Semibold','Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif; padding:0px; margin-top:9px; margin-bottom:19px"> <div style="font-family:'Microsoft YaHei UI','Microsoft YaHei',SimSun,'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif!important"> <span class="cl_CollapsibleArea_expanding LW_CollapsibleArea_Img" style="border-width:0px; vertical-align:middle; margin-bottom:0px; float:left; margin-top:12px; display:block; width:9px; height:12px; overflow:hidden"></span> <span class="LW_CollapsibleArea_Title" style="font-family:'Segoe UI Semibold','Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif; padding-left:10px; font-size:1.769em; display:block; overflow:hidden">通配符</span> <div class="LW_CollapsibleArea_HrDiv" style="padding-top:0px"> <hr class="LW_CollapsibleArea_Hr" style="border-style:none; color:rgb(229,229,229)"> </div> </div> </div> <div class="sectionblock" style="padding-left:15px; padding-bottom:20px"> <p style="color:rgb(42,42,42); margin-top:0px; margin-bottom:0px; padding-bottom:15px; line-height:18px"> <span id="mt53" class="sentence">通过使用通配符 (<span class="code" style="font-family:Consolas,Courier,monospace; color:rgb(0,100,0)">*</span>) 集合,不使用元素名即可引用元素。 </span><span id="mt54" class="sentence"><span class="code" style="font-family:Consolas,Courier,monospace; color:rgb(0,100,0)">*</span> 集合引用作为当前上下文的子级的所有元素,与名称无关。</span></p> <h3 class="subHeading" style="font-family:'Segoe UI Semibold','Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif; font-size:1.231em; font-weight:normal; margin:0px; padding-bottom:5px; padding-top:5px"> 示例</h3> <div class="subsection"> <div class="caption"></div> <div class="tableSection"> <table style="border-collapse:collapse; padding:0px; width:1008px; border:1px solid rgb(187,187,187)"> <tbody> <tr> <th style="border:1px solid rgb(187,187,187); margin:10px; padding:10px 8px; background-color:rgb(237,237,237); color:rgb(99,99,99); font-family:'Microsoft YaHei UI','Microsoft YaHei',SimSun,'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif!important"> <p style="color:rgb(42,42,42); margin-top:0px; margin-bottom:0px; padding-bottom:0px; line-height:18px"> <span id="mt55" class="sentence">表达式</span></p> </th> <th style="border:1px solid rgb(187,187,187); margin:10px; padding:10px 8px; background-color:rgb(237,237,237); color:rgb(99,99,99); font-family:'Microsoft YaHei UI','Microsoft YaHei',SimSun,'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif!important"> <p style="color:rgb(42,42,42); margin-top:0px; margin-bottom:0px; padding-bottom:0px; line-height:18px"> <span id="mt56" class="sentence">引用</span></p> </th> </tr> <tr> <td style="font-family:'Microsoft YaHei UI','Microsoft YaHei',SimSun,'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif!important; border:1px solid rgb(187,187,187); margin:10px; padding:10px 8px; color:rgb(42,42,42); vertical-align:top"> <p style="margin-top:0px; margin-bottom:0px; padding-bottom:0px; line-height:18px"> <span class="code" style="font-family:Consolas,Courier,monospace; color:rgb(0,100,0)">author/*</span></p> </td> <td style="font-family:'Microsoft YaHei UI','Microsoft YaHei',SimSun,'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif!important; border:1px solid rgb(187,187,187); margin:10px; padding:10px 8px; color:rgb(42,42,42); vertical-align:top"> <p style="margin-top:0px; margin-bottom:0px; padding-bottom:0px; line-height:18px"> <span id="mt57" class="sentence"><span class="code" style="font-family:Consolas,Courier,monospace; color:rgb(0,100,0)"><author></span> 元素的所有元素子级。</span></p> </td> </tr> <tr> <td style="font-family:'Microsoft YaHei UI','Microsoft YaHei',SimSun,'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif!important; border:1px solid rgb(187,187,187); margin:10px; padding:10px 8px; color:rgb(42,42,42); vertical-align:top"> <p style="margin-top:0px; margin-bottom:0px; padding-bottom:0px; line-height:18px"> <span class="code" style="font-family:Consolas,Courier,monospace; color:rgb(0,100,0)">book/*/last-name</span></p> </td> <td style="font-family:'Microsoft YaHei UI','Microsoft YaHei',SimSun,'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif!important; border:1px solid rgb(187,187,187); margin:10px; padding:10px 8px; color:rgb(42,42,42); vertical-align:top"> <p style="margin-top:0px; margin-bottom:0px; padding-bottom:0px; line-height:18px"> <span id="mt58" class="sentence">所有作为 <span class="code" style="font-family:Consolas,Courier,monospace; color:rgb(0,100,0)"><book></span> 元素孙代的 <span class="code" style="font-family:Consolas,Courier,monospace; color:rgb(0,100,0)"><last–name></span> 元素。</span></p> </td> </tr> <tr> <td style="font-family:'Microsoft YaHei UI','Microsoft YaHei',SimSun,'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif!important; border:1px solid rgb(187,187,187); margin:10px; padding:10px 8px; color:rgb(42,42,42); vertical-align:top"> <p style="margin-top:0px; margin-bottom:0px; padding-bottom:0px; line-height:18px"> <span class="code" style="font-family:Consolas,Courier,monospace; color:rgb(0,100,0)">*/*</span></p> </td> <td style="font-family:'Microsoft YaHei UI','Microsoft YaHei',SimSun,'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif!important; border:1px solid rgb(187,187,187); margin:10px; padding:10px 8px; color:rgb(42,42,42); vertical-align:top"> <p style="margin-top:0px; margin-bottom:0px; padding-bottom:0px; line-height:18px"> <span id="mt59" class="sentence">当前上下文的所有孙级元素。</span></p> </td> </tr> <tr> <td style="font-family:'Microsoft YaHei UI','Microsoft YaHei',SimSun,'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif!important; border:1px solid rgb(187,187,187); margin:10px; padding:10px 8px; color:rgb(42,42,42); vertical-align:top"> <p style="margin-top:0px; margin-bottom:0px; padding-bottom:0px; line-height:18px"> <span class="code" style="font-family:Consolas,Courier,monospace; color:rgb(0,100,0)">my:book</span></p> </td> <td style="font-family:'Microsoft YaHei UI','Microsoft YaHei',SimSun,'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif!important; border:1px solid rgb(187,187,187); margin:10px; padding:10px 8px; color:rgb(42,42,42); vertical-align:top"> <p style="margin-top:0px; margin-bottom:0px; padding-bottom:0px; line-height:18px"> <span id="mt60" class="sentence"><span class="code" style="font-family:Consolas,Courier,monospace; color:rgb(0,100,0)">my</span> 命名空间中的 <span class="code" style="font-family:Consolas,Courier,monospace; color:rgb(0,100,0)"><book></span> 元素。</span></p> </td> </tr> <tr> <td style="font-family:'Microsoft YaHei UI','Microsoft YaHei',SimSun,'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif!important; border:1px solid rgb(187,187,187); margin:10px; padding:10px 8px; color:rgb(42,42,42); vertical-align:top"> <p style="margin-top:0px; margin-bottom:0px; padding-bottom:0px; line-height:18px"> <span class="code" style="font-family:Consolas,Courier,monospace; color:rgb(0,100,0)">my:*</span></p> </td> <td style="font-family:'Microsoft YaHei UI','Microsoft YaHei',SimSun,'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif!important; border:1px solid rgb(187,187,187); margin:10px; padding:10px 8px; color:rgb(42,42,42); vertical-align:top"> <p style="margin-top:0px; margin-bottom:0px; padding-bottom:0px; line-height:18px"> <span id="mt61" class="sentence"><span class="code" style="font-family:Consolas,Courier,monospace; color:rgb(0,100,0)">my</span> 命名空间中的所有元素。</span></p> </td> </tr> </tbody> </table> </div> <p style="color:rgb(42,42,42); margin-top:0px; margin-bottom:0px; padding-bottom:15px; line-height:18px"> <span id="mt62" class="sentence">注意,不支持模式 <span class="code" style="font-family:Consolas,Courier,monospace; color:rgb(0,100,0)">*:book</span>。</span></p> </div> </div> </div> <div> <div class="LW_CollapsibleArea_TitleDiv" style="font-family:'Segoe UI Semibold','Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif; padding:0px; margin-top:9px; margin-bottom:19px"> <div style="font-family:'Microsoft YaHei UI','Microsoft YaHei',SimSun,'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif!important"> <span class="cl_CollapsibleArea_expanding LW_CollapsibleArea_Img" style="border-width:0px; vertical-align:middle; margin-bottom:0px; float:left; margin-top:12px; display:block; width:9px; height:12px; overflow:hidden"></span> <span class="LW_CollapsibleArea_Title" style="font-family:'Segoe UI Semibold','Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif; padding-left:10px; font-size:1.769em; display:block; overflow:hidden">特性</span> <div class="LW_CollapsibleArea_HrDiv" style="padding-top:0px"> <hr class="LW_CollapsibleArea_Hr" style="border-style:none; color:rgb(229,229,229)"> </div> </div> </div> <div class="sectionblock" style="padding-left:15px; padding-bottom:20px"> <p style="color:rgb(42,42,42); margin-top:0px; margin-bottom:0px; padding-bottom:15px; line-height:18px"> <span id="mt63" class="sentence">XPath 使用 <span class="code" style="font-family:Consolas,Courier,monospace; color:rgb(0,100,0)">@</span> 符号表示属性名。 </span><span id="mt64" class="sentence">属性和子元素应公平对待,两种类型之间的功能应尽可能相当。</span></p> <div class="alert" style="border:1px solid rgb(187,187,187); background-color:rgb(252,254,197); margin-bottom:10px"> <table style="border-collapse:collapse; padding:0px; border:1px solid rgb(187,187,187); width:1006px"> <tbody> <tr> <th style="border:1px solid rgb(187,187,187); margin:10px; padding:10px 11px 5px; background-color:rgb(237,237,237); color:rgb(99,99,99); border-collapse:collapse; border-spacing:0px; font-family:'Microsoft YaHei UI','Microsoft YaHei',SimSun,'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif!important">  <strong>注意</strong></th> </tr> <tr> <td style="font-family:'Microsoft YaHei UI','Microsoft YaHei',SimSun,'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif!important; border:1px solid rgb(187,187,187); margin:10px; padding:10px 8px; color:rgb(42,42,42); vertical-align:top"> <p style="margin-top:0px; margin-bottom:0px; padding-bottom:0px; line-height:18px"> <span id="mt65" class="sentence">属性不能包含子元素,所以,如果对属性应用路径运算符,将出现语法错误。 </span><span id="mt66" class="sentence">此外,不能对属性应用索引,因为根据定义,不为属性定义任何顺序。</span></p> </td> </tr> </tbody> </table> </div> <h3 class="subHeading" style="font-family:'Segoe UI Semibold','Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif; font-size:1.231em; font-weight:normal; margin:0px; padding-bottom:5px; padding-top:5px"> 示例</h3> <div class="subsection"> <div class="caption"></div> <div class="tableSection"> <table style="border-collapse:collapse; padding:0px; width:1008px; border:1px solid rgb(187,187,187)"> <tbody> <tr> <th style="border:1px solid rgb(187,187,187); margin:10px; padding:10px 8px; background-color:rgb(237,237,237); color:rgb(99,99,99); font-family:'Microsoft YaHei UI','Microsoft YaHei',SimSun,'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif!important"> <p style="color:rgb(42,42,42); margin-top:0px; margin-bottom:0px; padding-bottom:0px; line-height:18px"> <span id="mt67" class="sentence">表达式</span></p> </th> <th style="border:1px solid rgb(187,187,187); margin:10px; padding:10px 8px; background-color:rgb(237,237,237); color:rgb(99,99,99); font-family:'Microsoft YaHei UI','Microsoft YaHei',SimSun,'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif!important"> <p style="color:rgb(42,42,42); margin-top:0px; margin-bottom:0px; padding-bottom:0px; line-height:18px"> <span id="mt68" class="sentence">引用</span></p> </th> </tr> <tr> <td style="font-family:'Microsoft YaHei UI','Microsoft YaHei',SimSun,'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif!important; border:1px solid rgb(187,187,187); margin:10px; padding:10px 8px; color:rgb(42,42,42); vertical-align:top"> <p style="margin-top:0px; margin-bottom:0px; padding-bottom:0px; line-height:18px"> <span class="code" style="font-family:Consolas,Courier,monospace; color:rgb(0,100,0)">@style</span></p> </td> <td style="font-family:'Microsoft YaHei UI','Microsoft YaHei',SimSun,'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif!important; border:1px solid rgb(187,187,187); margin:10px; padding:10px 8px; color:rgb(42,42,42); vertical-align:top"> <p style="margin-top:0px; margin-bottom:0px; padding-bottom:0px; line-height:18px"> <span id="mt69" class="sentence">当前元素上下文的 <span class="code" style="font-family:Consolas,Courier,monospace; color:rgb(0,100,0)">style</span> 属性。</span></p> </td> </tr> <tr> <td style="font-family:'Microsoft YaHei UI','Microsoft YaHei',SimSun,'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif!important; border:1px solid rgb(187,187,187); margin:10px; padding:10px 8px; color:rgb(42,42,42); vertical-align:top"> <p style="margin-top:0px; margin-bottom:0px; padding-bottom:0px; line-height:18px"> <span class="code" style="font-family:Consolas,Courier,monospace; color:rgb(0,100,0)">price/@exchange</span></p> </td> <td style="font-family:'Microsoft YaHei UI','Microsoft YaHei',SimSun,'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif!important; border:1px solid rgb(187,187,187); margin:10px; padding:10px 8px; color:rgb(42,42,42); vertical-align:top"> <p style="margin-top:0px; margin-bottom:0px; padding-bottom:0px; line-height:18px"> <span id="mt70" class="sentence">当前上下文内的 <span class="code" style="font-family:Consolas,Courier,monospace; color:rgb(0,100,0)"><price></span> 元素的 <span class="code" style="font-family:Consolas,Courier,monospace; color:rgb(0,100,0)">exchange</span> 属性。</span></p> </td> </tr> <tr> <td style="font-family:'Microsoft YaHei UI','Microsoft YaHei',SimSun,'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif!important; border:1px solid rgb(187,187,187); margin:10px; padding:10px 8px; color:rgb(42,42,42); vertical-align:top"> <p style="margin-top:0px; margin-bottom:0px; padding-bottom:0px; line-height:18px"> <span class="code" style="font-family:Consolas,Courier,monospace; color:rgb(0,100,0)">book/@style</span></p> </td> <td style="font-family:'Microsoft YaHei UI','Microsoft YaHei',SimSun,'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif!important; border:1px solid rgb(187,187,187); margin:10px; padding:10px 8px; color:rgb(42,42,42); vertical-align:top"> <p style="margin-top:0px; margin-bottom:0px; padding-bottom:0px; line-height:18px"> <span id="mt71" class="sentence">所有 <span class="code" style="font-family:Consolas,Courier,monospace; color:rgb(0,100,0)"><book> </span>元素的 <span class="code" style="font-family:Consolas,Courier,monospace; color:rgb(0,100,0)">style</span> 属性。</span></p> </td> </tr> </tbody> </table> </div> <p style="color:rgb(42,42,42); margin-top:0px; margin-bottom:0px; padding-bottom:15px; line-height:18px"> <span id="mt72" class="sentence">注意,以下示例无效,因为属性不能包含任何子级。</span></p> <div id="code-snippet-1" class="codeSnippetContainer" style="min-width:260px; clear:both"> <div class="codeSnippetContainerTabs" style="vertical-align:middle; height:23px; position:relative; z-index:1"> </div> <div class="codeSnippetContainerCodeContainer" style="border:1px solid rgb(147,147,147); clear:both; margin-bottom:12px; position:relative; top:-1px"> <div class="codeSnippetToolBar" style="width:auto; height:auto"> <div class="codeSnippetToolBarText" style="float:right; top:-8px; position:relative; width:auto; padding-left:0px; padding-right:0px; height:0px; vertical-align:top"> </div> </div> <div id="CodeSnippetContainerCode_b47e5c14-ec38-48c6-820d-171eb9b00514" class="codeSnippetContainerCode" style="width:auto; margin:0px; padding:10px 21px"> <div style="padding:0px; margin:0px"> <pre style="padding:5px; margin-top:0px; margin-bottom:0px; overflow:auto; word-wrap:normal; font-family:Consolas,Courier,monospace!important">price/@exchange/total </pre> </div> </div> </div> </div> </div> </div> </div> <div> <div class="LW_CollapsibleArea_TitleDiv" style="font-family:'Segoe UI Semibold','Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif; padding:0px; margin-top:9px; margin-bottom:19px"> <div style="font-family:'Microsoft YaHei UI','Microsoft YaHei',SimSun,'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif!important"> <span class="cl_CollapsibleArea_expanding LW_CollapsibleArea_Img" style="border-width:0px; vertical-align:middle; margin-bottom:0px; float:left; margin-top:12px; display:block; width:9px; height:12px; overflow:hidden"></span> <span class="LW_CollapsibleArea_Title" style="font-family:'Segoe UI Semibold','Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif; padding-left:10px; font-size:1.769em; display:block; overflow:hidden">查找多个属性</span> <div class="LW_CollapsibleArea_HrDiv" style="padding-top:0px"> <hr class="LW_CollapsibleArea_Hr" style="border-style:none; color:rgb(229,229,229)"> </div> </div> </div> <div class="sectionblock" style="padding-left:15px; padding-bottom:20px"> <p style="color:rgb(42,42,42); margin-top:0px; margin-bottom:0px; padding-bottom:15px; line-height:18px"> <span id="mt73" class="sentence">使用 <span class="code" style="font-family:Consolas,Courier,monospace; color:rgb(0,100,0)">@*</span> 可以返回某个元素的所有属性。 </span><span id="mt74" class="sentence">对于将属性作为记录中的字段的应用程序,此表达式可能非常有用。</span></p> <h3 class="subHeading" style="font-family:'Segoe UI Semibold','Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif; font-size:1.231em; font-weight:normal; margin:0px; padding-bottom:5px; padding-top:5px"> 示例</h3> <div class="subsection"> <div class="caption"></div> <div class="tableSection"> <table style="border-collapse:collapse; padding:0px; width:1008px; border:1px solid rgb(187,187,187)"> <tbody> <tr> <th style="border:1px solid rgb(187,187,187); margin:10px; padding:10px 8px; background-color:rgb(237,237,237); color:rgb(99,99,99); font-family:'Microsoft YaHei UI','Microsoft YaHei',SimSun,'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif!important"> <p style="color:rgb(42,42,42); margin-top:0px; margin-bottom:0px; padding-bottom:0px; line-height:18px"> <span id="mt75" class="sentence">表达式</span></p> </th> <th style="border:1px solid rgb(187,187,187); margin:10px; padding:10px 8px; background-color:rgb(237,237,237); color:rgb(99,99,99); font-family:'Microsoft YaHei UI','Microsoft YaHei',SimSun,'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif!important"> <p style="color:rgb(42,42,42); margin-top:0px; margin-bottom:0px; padding-bottom:0px; line-height:18px"> <span id="mt76" class="sentence">引用</span></p> </th> </tr> <tr> <td style="font-family:'Microsoft YaHei UI','Microsoft YaHei',SimSun,'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif!important; border:1px solid rgb(187,187,187); margin:10px; padding:10px 8px; color:rgb(42,42,42); vertical-align:top"> <p style="margin-top:0px; margin-bottom:0px; padding-bottom:0px; line-height:18px"> <span class="code" style="font-family:Consolas,Courier,monospace; color:rgb(0,100,0)">@*</span></p> </td> <td style="font-family:'Microsoft YaHei UI','Microsoft YaHei',SimSun,'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif!important; border:1px solid rgb(187,187,187); margin:10px; padding:10px 8px; color:rgb(42,42,42); vertical-align:top"> <p style="margin-top:0px; margin-bottom:0px; padding-bottom:0px; line-height:18px"> <span id="mt77" class="sentence">当前上下文节点的所有属性。</span></p> </td> </tr> <tr> <td style="font-family:'Microsoft YaHei UI','Microsoft YaHei',SimSun,'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif!important; border:1px solid rgb(187,187,187); margin:10px; padding:10px 8px; color:rgb(42,42,42); vertical-align:top"> <p style="margin-top:0px; margin-bottom:0px; padding-bottom:0px; line-height:18px"> <span class="code" style="font-family:Consolas,Courier,monospace; color:rgb(0,100,0)">@my:*</span></p> </td> <td style="font-family:'Microsoft YaHei UI','Microsoft YaHei',SimSun,'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif!important; border:1px solid rgb(187,187,187); margin:10px; padding:10px 8px; color:rgb(42,42,42); vertical-align:top"> <p style="margin-top:0px; margin-bottom:0px; padding-bottom:0px; line-height:18px"> <span id="mt78" class="sentence"><span class="code" style="font-family:Consolas,Courier,monospace; color:rgb(0,100,0)">my</span> 命名空间中的所有属性。 </span><span id="mt79" class="sentence">不包括 <span class="code" style="font-family:Consolas,Courier,monospace; color:rgb(0,100,0)">my</span> 命名空间中的元素的未限定特性。</span></p> </td> </tr> </tbody> </table> </div> <p style="color:rgb(42,42,42); margin-top:0px; margin-bottom:0px; padding-bottom:15px; line-height:18px"> <span id="mt80" class="sentence">注意,不支持模式 <span class="code" style="font-family:Consolas,Courier,monospace; color:rgb(0,100,0)">@*:title</span>。</span></p> <p style="color:rgb(42,42,42); margin-top:0px; margin-bottom:0px; padding-bottom:15px; line-height:18px"> 更加详细内容见微软网站 http://msdn.microsoft.com/zh-cn/library/ms256471(v=vs.110).aspx</p> <p style="color:rgb(42,42,42); margin-top:0px; margin-bottom:0px; padding-bottom:15px; line-height:18px"> <br> </p> <p style="color:rgb(42,42,42); margin-top:0px; margin-bottom:0px; padding-bottom:15px; line-height:18px"> Dom4j使用xpath的例子</p> <p style="color:rgb(42,42,42); margin-top:0px; margin-bottom:0px; padding-bottom:15px; line-height:18px"> 下面的例子是取出子文件夹的ID和文件夹名的集合</p> <p style="color:rgb(42,42,42); margin-top:0px; margin-bottom:0px; padding-bottom:15px; line-height:18px"> </p> <pre><code class="language-java">import java.util.Iterator; import java.util.List; import org.dom4j.Document; import org.dom4j.DocumentException; import org.dom4j.Element; import org.dom4j.io.SAXReader; /** * Test App * */ public class App { public static void main( String[] args ) throws DocumentException { xpathTest(); } /** * XPath syntax test method * @throws DocumentException */ @SuppressWarnings("rawtypes") private static void xpathTest() throws DocumentException { SAXReader reader = new SAXReader(); Document document = reader.read("d:/2.xml"); Element root = document.getRootElement(); String xpath = "/folder/fields/folder"; List lstNodes = root.selectNodes(xpath); for (Iterator ir = lstNodes.iterator(); ir.hasNext(); ) { Element elm = (Element)ir.next(); System.out.println(elm.attributeValue("id")); System.out.println(elm.selectSingleNode("fields/field[@name='NAME']").getText()); } } }</code></pre> <br> <p></p> </div> </div> </div> </div> </div> 上面例子用的2.xml如下 <br> <pre><code class="language-html"><?xml version="1.0"?> <folder id="1091" type="None"> <fields> <field name="NAME">General</field> <folder id="1092" > <fields> <field name="NAME">Test01</field> </fields> </folder> <folder id="1093" > <fields> <field name="NAME">Test02</field> </fields> </folder> </fields> </folder></code></pre> <br> <br> <p></p> <p><br> </p> </div> </div> </div> </div> </div> <!--PC和WAP自适应版--> <div id="SOHUCS" sid="1364623688179146752"></div> <script type="text/javascript" src="/views/front/js/chanyan.js"></script> <!-- 文章页-底部 动态广告位 --> <div class="youdao-fixed-ad" id="detail_ad_bottom"></div> </div> <div class="col-md-3"> <div class="row" id="ad"> <!-- 文章页-右侧1 动态广告位 --> <div id="right-1" class="col-lg-12 col-md-12 col-sm-4 col-xs-4 ad"> <div class="youdao-fixed-ad" id="detail_ad_1"> </div> </div> <!-- 文章页-右侧2 动态广告位 --> <div id="right-2" class="col-lg-12 col-md-12 col-sm-4 col-xs-4 ad"> <div class="youdao-fixed-ad" id="detail_ad_2"></div> </div> <!-- 文章页-右侧3 动态广告位 --> <div id="right-3" class="col-lg-12 col-md-12 col-sm-4 col-xs-4 ad"> <div class="youdao-fixed-ad" id="detail_ad_3"></div> </div> </div> </div> </div> </div> </div> <div class="container"> <h4 class="pt20 mb15 mt0 border-top">你可能感兴趣的:(xml,xml,xpath)</h4> <div id="paradigm-article-related"> <div class="recommend-post mb30"> <ul class="widget-links"> <li><a href="/article/1900667821621309440.htm" title="MyBatis-Plus接入和简单使用" target="_blank">MyBatis-Plus接入和简单使用</a> <span class="text-muted">测试开发小白变怪兽</span> <a class="tag" taget="_blank" href="/search/%E6%9C%8D%E5%8A%A1%E7%AB%AF/1.htm">服务端</a><a class="tag" taget="_blank" href="/search/mybatis/1.htm">mybatis</a> <div>如何接入https://baomidou.com/getting-started/简单使用方法使用MyBatis-Plus时,大多数场景下不需要编写XML和SQL,因为它提供了强大的通用CRUD操作和条件构造器。但以下情况可能需要手动编写SQL:1.不需要写XML/SQL的场景(1)通用CRUD操作MyBatis-Plus的BaseMapper接口已经内置了通用的增删改查方法,例如:userMap</div> </li> <li><a href="/article/1900654075574284288.htm" title="使用 UML 设计 XML 模式" target="_blank">使用 UML 设计 XML 模式</a> <span class="text-muted">langzhufeng</span> <a class="tag" taget="_blank" href="/search/uml/1.htm">uml</a><a class="tag" taget="_blank" href="/search/xml/1.htm">xml</a><a class="tag" taget="_blank" href="/search/extension/1.htm">extension</a><a class="tag" taget="_blank" href="/search/schema/1.htm">schema</a><a class="tag" taget="_blank" href="/search/string/1.htm">string</a><a class="tag" taget="_blank" href="/search/encoding/1.htm">encoding</a> <div>使用UML设计XML模式统一建模语言(UnifiedModelingLanguage,UML)是一种业界标准,当以面向对象的方法构建软件系统时,用它来对业务概念建模。就信息和命令的传输方面而言,近来XML已经愈发成为实现这些系统的关键因素。XML模式用于定义和限制被交换XML的本质,因此它成为了人们注意的焦点。本文讨论了UML在设计XML模式方面的用法,并为使用UML框架创建XML词汇表提供了一种</div> </li> <li><a href="/article/1900651805201723392.htm" title="xml" target="_blank">xml</a> <span class="text-muted">ColorPaper</span> <a class="tag" taget="_blank" href="/search/%E5%90%84%E9%A1%B9IT%E6%8A%80%E6%9C%AF/1.htm">各项IT技术</a><a class="tag" taget="_blank" href="/search/%E6%9D%82%E9%A1%B9/1.htm">杂项</a><a class="tag" taget="_blank" href="/search/xml/1.htm">xml</a><a class="tag" taget="_blank" href="/search/character/1.htm">character</a><a class="tag" taget="_blank" href="/search/attributes/1.htm">attributes</a><a class="tag" taget="_blank" href="/search/processing/1.htm">processing</a><a class="tag" taget="_blank" href="/search/schema/1.htm">schema</a><a class="tag" taget="_blank" href="/search/encoding/1.htm">encoding</a> <div>TheExtensibleMarkupLanguage(XML)isageneral-purposespecificationforcreatingcustommarkuplanguages.[1]Itisclassifiedasanextensiblelanguagebecauseitallowsitsuserstodefinetheirownelements.Itsprimarypurpose</div> </li> <li><a href="/article/1900649276267098112.htm" title="XMI(XML Metadata Interchange)和XML之间的关系" target="_blank">XMI(XML Metadata Interchange)和XML之间的关系</a> <span class="text-muted">huaqianzkh</span> <a class="tag" taget="_blank" href="/search/%E6%9E%B6%E6%9E%84%E7%90%86%E8%A7%A3%E4%B8%8E%E5%AE%9E%E8%B7%B5/1.htm">架构理解与实践</a><a class="tag" taget="_blank" href="/search/xml/1.htm">xml</a> <div>XMI(XMLMetadataInterchange)和XML之间的关系可以从以下几个方面进行阐述:一、定义与背景XML:XML(eXtensibleMarkupLanguage)是一种标记语言,被设计用来传输和存储数据。它是一种自描述的语言,即标签(tags)是由用户定义的,因此XML文档的结构和内容可以由创建者自行决定。XMI:XMI(XMLMetadataInterchange)是由OMG(</div> </li> <li><a href="/article/1900616979455209472.htm" title="Maven的安装配置" target="_blank">Maven的安装配置</a> <span class="text-muted">2301_82243979</span> <a class="tag" taget="_blank" href="/search/%E4%BD%9C%E8%80%85%5C%2F/1.htm">作者\/</a><a class="tag" taget="_blank" href="/search/maven/1.htm">maven</a><a class="tag" taget="_blank" href="/search/java/1.htm">java</a> <div>(注:文章是前段时间写的忘记发了,防止丢失在此记录一下)Maven是Apache下的纯Java开发的开源项目,是一个项目管理工具,使用Maven对项目进行构建,依赖管理。依赖管理就是一个项目中要使用第三方jar包才可以运行。Maven正是对这些jar包进行规范化管理,所以在Maven的项目中只需要在pom.xml中添加jar包的坐标,自动从Maven仓库中下载jar包,运行即可。Maven项目对比</div> </li> <li><a href="/article/1900599452977131520.htm" title="自动化测试:灵活书写XPATH定位路径" target="_blank">自动化测试:灵活书写XPATH定位路径</a> <span class="text-muted">ZJ_star_1220</span> <a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/html/1.htm">html</a><a class="tag" taget="_blank" href="/search/css/1.htm">css</a><a class="tag" taget="_blank" href="/search/%E5%89%8D%E7%AB%AF/1.htm">前端</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a> <div>进行UI自动化测试过程中XPATH定位是使用最多的定位方法,但是有时候直接复制出来的XPATH路径会比较长,所以就需要掌握一些更高级的方法,通过询问AI,最终得到了以下方法,感觉很有用,所以记录下来一、基础定位语法绝对路径与相对路径绝对路径:以/开头,从根节点逐层定位(如/html/body/div/input),路径长且易受页面结构调整影响相对路径:以//开头,直接定位目标元素(如//input</div> </li> <li><a href="/article/1900592390473838592.htm" title="使用Nexus从私服上传和下载依赖" target="_blank">使用Nexus从私服上传和下载依赖</a> <span class="text-muted">北省1332</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/%E6%9C%8D%E5%8A%A1%E5%99%A8/1.htm">服务器</a> <div>从私服中下载依赖【第一步】在maven的settings.xml中标签中配置,此时就需要注释掉aliyun的配置。nexus-heima*http://localhost:8081/repository/maven-public/【第二步】在nexus中设置允许匿名下载,如果不允许将不会从私服中下载依赖如果私服中没有对应的jar,会去中央仓库下载,速度很慢。可以配置让私服去阿里云中下载依赖。从私服</div> </li> <li><a href="/article/1900587981727657984.htm" title="Mybatis的基本使用" target="_blank">Mybatis的基本使用</a> <span class="text-muted">学c真好玩</span> <a class="tag" taget="_blank" href="/search/mybatis/1.htm">mybatis</a> <div>MyBatis简介MyBatis用于持久层框架,持久层是对数据库操作的部分,前版本iBatis由Apache软件基金组织进行更名并维护。特点:简化数据库的操作SQL映射灵活(半ORM框架)支持高级映射易于集成维护配置动态SQL缓存机制功能:替代JDBC,JDBC是java中提供的用于操作数据库的技术及方案数据库的连接控制难。连接池SQL语句硬编码。将sql语句存放到xml配置文件中参数传递问题。提</div> </li> <li><a href="/article/1900555182073245696.htm" title="MasterDetail页调试错误:CS0263" target="_blank">MasterDetail页调试错误:CS0263</a> <span class="text-muted">IT落英</span> <a class="tag" taget="_blank" href="/search/bug/1.htm">bug</a> <div>写WPF页面的逻辑的时候,遇到了这个问题,百度了好久,记录一下问题描述:MasterDetailPage分部声明不能指定不同的基类主要是xml的问题在XAML主页中是MasterDetailPage,而不是ContentPage。做出如下修改publicpartialclassMainPage:MasterDetailPage</div> </li> <li><a href="/article/1900508632756318208.htm" title="python脚本使用Bash指令的一种方式" target="_blank">python脚本使用Bash指令的一种方式</a> <span class="text-muted">xz1308579340</span> <a class="tag" taget="_blank" href="/search/python/1.htm">python</a> <div>print(name)print(read_content(name))infos.append(read_content(name))xml=os.path.join(dir,name)new_xml=new_dir+'/'+str(count)+'.xml'img=xml.replace('xml','png')new_img=new_dir+'/'+str(count)+'.png'wd='</div> </li> <li><a href="/article/1900501187870912512.htm" title="从零实现OSS阿里云图片上传:前端采用的vue3+element-plus,后端采用javaspingboot,实现上传图片到云,然后存储数据库链接能够回显的效果" target="_blank">从零实现OSS阿里云图片上传:前端采用的vue3+element-plus,后端采用javaspingboot,实现上传图片到云,然后存储数据库链接能够回显的效果</a> <span class="text-muted">绝顶少年</span> <a class="tag" taget="_blank" href="/search/%E9%98%BF%E9%87%8C%E4%BA%91/1.htm">阿里云</a><a class="tag" taget="_blank" href="/search/%E5%89%8D%E7%AB%AF/1.htm">前端</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E5%BA%93/1.htm">数据库</a> <div>后端(JavaSpringBoot)1.添加依赖在pom.xml中添加必要的依赖,包括阿里云OSSSDK、SpringBootWeb、MyBatis-Plus等:org.springframework.bootspring-boot-starter-webcom.baomidoumybatis-plus-boot-starter3.4.3.4com.aliyun.ossaliyun-sdk-oss</div> </li> <li><a href="/article/1900484416136867840.htm" title="ueditor图片上传跨域问题" target="_blank">ueditor图片上传跨域问题</a> <span class="text-muted">hello_simon</span> <a class="tag" taget="_blank" href="/search/javascript/1.htm">javascript</a><a class="tag" taget="_blank" href="/search/php/1.htm">php</a><a class="tag" taget="_blank" href="/search/ueditor/1.htm">ueditor</a><a class="tag" taget="_blank" href="/search/%E5%9B%BE%E7%89%87%E4%B8%8A%E4%BC%A0%E8%B7%A8%E5%9F%9F/1.htm">图片上传跨域</a> <div>ueditor置于A域,图片置于B域,B域需放flash跨域策略文件crossdomain.xml,如下修改ueditor配置文件ueditor.config.js//图片上传配置区,imageUrl:"http://abupload.xxx.com/imageUp.php"//图片上传提交地址,imagePath:"http://abupload.xxx.com/"</div> </li> <li><a href="/article/1900450620339449856.htm" title="原生微信小程序实现导航漫游(Tour)" target="_blank">原生微信小程序实现导航漫游(Tour)</a> <span class="text-muted">多喜乐 长安宁</span> <a class="tag" taget="_blank" href="/search/%E5%BE%AE%E4%BF%A1%E5%B0%8F%E7%A8%8B%E5%BA%8F/1.htm">微信小程序</a><a class="tag" taget="_blank" href="/search/%E5%BE%AE%E4%BF%A1%E5%B0%8F%E7%A8%8B%E5%BA%8F/1.htm">微信小程序</a><a class="tag" taget="_blank" href="/search/%E5%B0%8F%E7%A8%8B%E5%BA%8F/1.htm">小程序</a> <div>效果:小程序实现导航漫游1、组件miniprogram/components/tour/index.wxml{{guideList[index].tips}}{{index+1}}/{{guideList.length}}跳过0}}">上一步{{index===guideList.length-1?'完成':'下一步'}}miniprogram/components/tour/index.ts//</div> </li> <li><a href="/article/1900427419941138432.htm" title="spring 的model repository service controller的功能" target="_blank">spring 的model repository service controller的功能</a> <span class="text-muted">LCY133</span> <a class="tag" taget="_blank" href="/search/web%E5%BC%80%E5%8F%91/1.htm">web开发</a><a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a><a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/%E5%90%8E%E7%AB%AF/1.htm">后端</a> <div>1.Controller层(控制层)•功能:负责接收和处理HTTP请求,协调客户端与业务逻辑之间的交互。•核心职责:•请求处理:解析HTTP请求参数(如URL参数、Body数据、Headers)。•路由分发:根据请求路径(@RequestMapping)调用对应的Service方法。•响应生成:返回格式化数据(如JSON、XML)或视图(如HTML页面)。•输入校验:验证请求参数的合法性(如使用@</div> </li> <li><a href="/article/1900411666139508736.htm" title="【从零开始学习计算机科学】数据库系统(十)XML、XPATH、XQuery与XML数据库" target="_blank">【从零开始学习计算机科学】数据库系统(十)XML、XPATH、XQuery与XML数据库</a> <span class="text-muted">贫苦游商</span> <a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E5%BA%93/1.htm">数据库</a><a class="tag" taget="_blank" href="/search/%E5%AD%A6%E4%B9%A0/1.htm">学习</a><a class="tag" taget="_blank" href="/search/xml/1.htm">xml</a><a class="tag" taget="_blank" href="/search/xpath/1.htm">xpath</a><a class="tag" taget="_blank" href="/search/xml%E6%95%B0%E6%8D%AE%E5%BA%93/1.htm">xml数据库</a><a class="tag" taget="_blank" href="/search/xquery/1.htm">xquery</a><a class="tag" taget="_blank" href="/search/sql/1.htm">sql</a> <div>【从零开始学习计算机科学】数据库系统(十)XML、XPATH、XQuery与XML数据库XML基础知识元素属性Namespaces文档类型定义(DTD)文档类型定义(DTD)XML数据文档的树模型XML树模型的生成方式Xpath语言Xpath常用的标记XQuery语言XML基础知识XML是一种语言,更是一种适合灵活描述各种办半结构化的数据和结构的好工具。在一应用程序与另一应用程序需通信(交换数据)</div> </li> <li><a href="/article/1900386554266841088.htm" title="XPath元素定位实践案例:从基础到高阶的实战解析" target="_blank">XPath元素定位实践案例:从基础到高阶的实战解析</a> <span class="text-muted">测试渣</span> <a class="tag" taget="_blank" href="/search/selenium/1.htm">selenium</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E8%87%AA%E5%8A%A8%E5%8C%96/1.htm">自动化</a> <div>引言在软件测试与自动化领域,元素定位是实现高效测试的核心能力。随着Web和移动应用的复杂性提升,传统的ID、类名等定位方式面临动态生成、元素嵌套过深等挑战。XPath作为一种灵活且强大的定位语言,通过路径表达式与逻辑运算符的组合,能够精准定位复杂场景下的元素。本文结合多个真实案例,深入解析XPath的基础语法、高阶技巧及实战应用,帮助读者掌握这一关键技能。一、XPath基础语法与定位策略1.1XP</div> </li> <li><a href="/article/1900340670313328640.htm" title="SpringCloud 打包的 .jar 运行时,不能按日志配置进行输出日志" target="_blank">SpringCloud 打包的 .jar 运行时,不能按日志配置进行输出日志</a> <span class="text-muted">tvrddmss</span> <a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a><a class="tag" taget="_blank" href="/search/cloud/1.htm">cloud</a><a class="tag" taget="_blank" href="/search/jar/1.htm">jar</a><a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a> <div>1、问题:springcloud打包的.jar文件在运行时,不能按日志配置进行输出日志文件2、查到问题来自nacos,与springcloud的日志冲突,在运行时指定日志配置文件即可。java-Dlogging.config="logback-spring.xml"-jardemo-1.0-SNAPSHOT.jar</div> </li> <li><a href="/article/1900337770216353792.htm" title="ArcGIS切片缓存目录结构及配置文件说明" target="_blank">ArcGIS切片缓存目录结构及配置文件说明</a> <span class="text-muted">笑轩辕</span> <a class="tag" taget="_blank" href="/search/ArcGIS%E8%BD%AF%E4%BB%B6%E4%BD%BF%E7%94%A8/1.htm">ArcGIS软件使用</a><a class="tag" taget="_blank" href="/search/%E5%88%87%E7%89%87%E7%BC%93%E5%AD%98/1.htm">切片缓存</a><a class="tag" taget="_blank" href="/search/ArcGIS/1.htm">ArcGIS</a><a class="tag" taget="_blank" href="/search/Server/1.htm">Server</a> <div>目录缓存目录结构conf.cdi文件:conf.properties文件:conf.xml文件:ArcGIS切片缓存目录:3个配置文件和图片目录缓存目录结构服务名//Map//-_alllayers//服务名//Map//【1】conf.cdi主要记录范围,等于所切图层的范围,平面坐标显示【2】conf.properties固定【3】conf.xml包含参考系、起始点坐标、瓦片尺寸、读取切片原点、</div> </li> <li><a href="/article/1900312053738958848.htm" title="python selenium鼠标点击时、获取元素id_Python+selenium 获取验证信息" target="_blank">python selenium鼠标点击时、获取元素id_Python+selenium 获取验证信息</a> <span class="text-muted">weixin_39623271</span> <a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/selenium%E9%BC%A0%E6%A0%87%E7%82%B9%E5%87%BB%E6%97%B6/1.htm">selenium鼠标点击时</a><a class="tag" taget="_blank" href="/search/%E8%8E%B7%E5%8F%96%E5%85%83%E7%B4%A0id/1.htm">获取元素id</a> <div>获取页面信息1.获取URLurl=driver.current_url2.获取titletitle=driver.title3.获取texttext=driver.find_element_by_xpath("//*[@id='u1']/a[2]").text4.获取浏览器窗口大小size=driver.get_window_size()5.获取定位元素是否被选中,返回布尔值。适用于下拉框(收起状</div> </li> <li><a href="/article/1900298925198340096.htm" title="爬虫中一些有用的用法" target="_blank">爬虫中一些有用的用法</a> <span class="text-muted">才不是小emo的小杨</span> <a class="tag" taget="_blank" href="/search/%E7%88%AC%E8%99%AB/1.htm">爬虫</a><a class="tag" taget="_blank" href="/search/xpath/1.htm">xpath</a> <div>文本和标签在一个级别下如果文本和a标签在一个级别下比如:#获取a标签后的第一个文本节点text_node=a.xpath('following-sibling::text()[1]')[0].strip()将xpath的html代码转换成字符串etree.tostring(root,pretty_print=True,encoding="utf-8")获取所有同级标签的最后一个data_list=</div> </li> <li><a href="/article/1900294887346073600.htm" title="Spring Boot项目中集成阿里云短信服务" target="_blank">Spring Boot项目中集成阿里云短信服务</a> <span class="text-muted">山高自有客行路</span> <a class="tag" taget="_blank" href="/search/%23/1.htm">#</a><a class="tag" taget="_blank" href="/search/Springboot/1.htm">Springboot</a><a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a><a class="tag" taget="_blank" href="/search/boot/1.htm">boot</a><a class="tag" taget="_blank" href="/search/%E9%98%BF%E9%87%8C%E4%BA%91/1.htm">阿里云</a><a class="tag" taget="_blank" href="/search/%E5%90%8E%E7%AB%AF/1.htm">后端</a> <div>1.导入阿里云依赖首先,在你的pom.xml文件中添加阿里云短信服务的Maven依赖:com.aliyundysmsapi201705252.0.24确保你已经包含了其他必要的依赖,如MySQL驱动和MyBatis:mysqlmysql-connector-javaruntimeorg.mybatis.spring.bootmybatis-spring-boot-starter2.2.0org.p</div> </li> <li><a href="/article/1900290981199147008.htm" title="Spring Boot集成EasyExcel" target="_blank">Spring Boot集成EasyExcel</a> <span class="text-muted">山高自有客行路</span> <a class="tag" taget="_blank" href="/search/%23/1.htm">#</a><a class="tag" taget="_blank" href="/search/Springboot/1.htm">Springboot</a><a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a><a class="tag" taget="_blank" href="/search/boot/1.htm">boot</a><a class="tag" taget="_blank" href="/search/%E5%90%8E%E7%AB%AF/1.htm">后端</a> <div>1.初始化SpringBoot项目首先,使用SpringInitializr(https://start.spring.io/)生成一个基本的SpringBoot项目。选择以下依赖项:SpringWebLombok(用于减少样板代码)SLF4J(用于日志记录)2.添加依赖在你的pom.xml文件中添加EasyExcel的Maven依赖。确保版本号是最新的,你可以访问Maven仓库来获取最新版。co</div> </li> <li><a href="/article/1900264147325612032.htm" title="Spring 面向切面编程 XML 配置实现" target="_blank">Spring 面向切面编程 XML 配置实现</a> <span class="text-muted">我是大头鸟</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a><a class="tag" taget="_blank" href="/search/xml/1.htm">xml</a><a class="tag" taget="_blank" href="/search/java/1.htm">java</a> <div>Spring支持AOP,并且可以通过XML配置来实现。相关标签介绍:aop:config注明开始配置aop,是配置的开始标签aop:aspect配置切面ref属性是引用相关切面类Bean的idaop:point-cut定义切点expression是具体的表达式id是切点的标识aop:before定义前置通知method是要执行的方法pointcut-ref为引用的aop-point-cut定义的i</div> </li> <li><a href="/article/1900233133979136000.htm" title="封装AJAX(带详细注释)" target="_blank">封装AJAX(带详细注释)</a> <span class="text-muted">Rverdoser</span> <a class="tag" taget="_blank" href="/search/okhttp/1.htm">okhttp</a> <div>封装AJAX请求是前端开发中常见的需求,可以帮助我们简化代码,提高可重用性。下面我将通过JavaScript(使用XMLHttpRequest对象)和现代JavaScript(使用FetchAPI)两种方式来展示如何封装AJAX请求。1.使用XMLHttpRequest封装AJAXfunctionajax(method,url,data,callback){//创建XMLHttpRequest对象</div> </li> <li><a href="/article/1900228095936360448.htm" title="RocketMQ开发实战篇" target="_blank">RocketMQ开发实战篇</a> <span class="text-muted">Jeremy_1022</span> <a class="tag" taget="_blank" href="/search/RocketMQ/1.htm">RocketMQ</a><a class="tag" taget="_blank" href="/search/rocketmq/1.htm">rocketmq</a> <div>一、生产者开发指南1.JavaAPI使用详解在使用RocketMQ进行消息生产时,首先需要引入相关的依赖。在Maven项目中,可以在pom.xml文件中添加以下依赖:org.apache.rocketmqrocketmq-client4.9.0接下来,创建一个简单的生产者示例:importorg.apache.rocketmq.client.producer.DefaultMQProducer;i</div> </li> <li><a href="/article/1900191288033079296.htm" title="appium入坑必备--详解uiautomator2,让你摆脱usb_appium uiautomator2" target="_blank">appium入坑必备--详解uiautomator2,让你摆脱usb_appium uiautomator2</a> <span class="text-muted">weixin_45933550</span> <a class="tag" taget="_blank" href="/search/appium/1.htm">appium</a><a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a> <div>APP元素定位+基本工具介绍万字详解基本操作uc-devtools与Airtest工具使用目录UiAutomatorUiautomator2环境搭建常用操作连接设备Wifi连接USB连接定位工具定位元素启动应用停止应用查包名定位方式ResourceId定位Text定位Description定位ClassName定位xpath定位坐标定位重复元素定位截图文件推送与拉取常用鼠标操作滑动屏幕解锁屏幕获取</div> </li> <li><a href="/article/1900165820978360320.htm" title="playWright学习总结" target="_blank">playWright学习总结</a> <span class="text-muted">one day321</span> <a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a> <div>注意,这里并没有学过selenium自动化。playwright对比selenium来说,不需要不断下载驱动。且playWright最大的优点是可以录制操作,并自动生成自动化脚本。视频:快速上手-3-示例_哔哩哔哩_bilibili资料:Xpath/Role/视觉定位方法-白月黑羽安装:直接使用命令安装:pipinstallplaywright安装需要的浏览器:playwrightinstall安</div> </li> <li><a href="/article/1900163296925904896.htm" title="MyBatis 的核心配置文件是干什么的? 它的结构是怎样的? 哪些是必须配置的,哪些是可选的?" target="_blank">MyBatis 的核心配置文件是干什么的? 它的结构是怎样的? 哪些是必须配置的,哪些是可选的?</a> <span class="text-muted">冰糖心书房</span> <a class="tag" taget="_blank" href="/search/Mybatis/1.htm">Mybatis</a><a class="tag" taget="_blank" href="/search/%E6%BA%90%E7%A0%81%E7%B3%BB%E5%88%97/1.htm">源码系列</a><a class="tag" taget="_blank" href="/search/mybatis/1.htm">mybatis</a> <div>MyBatis的核心配置文件(通常命名为mybatis-config.xml)是MyBatis应用程序的入口点,它定义了MyBatis的全局配置信息。核心配置文件的作用:配置MyBatis的运行时行为:通过标签设置全局参数,控制MyBatis的各种行为,例如是否开启缓存、是否使用延迟加载、是否自动映射等。配置数据源和事务管理器:通过标签配置数据库连接信息和事务管理方式。注册类型别名:通过标签为Ja</div> </li> <li><a href="/article/1900145018115518464.htm" title="Schema" target="_blank">Schema</a> <span class="text-muted">superXX07</span> <div>1.最简单的Schema文档如何写一个最简单的XMLSchema文档呢?首先,我们写出一个最简单的XML文档。hello.xml-------------------HelloWorld!!hello.xsd----------XMLSchema文档后缀名是.xsd,完全符合XML语法,根元素是schema,命名空间xmlns:xsd="http://www.w3.org/2001/XMLSche</div> </li> <li><a href="/article/1900032294819786752.htm" title="替换word模板内容 Java实现" target="_blank">替换word模板内容 Java实现</a> <span class="text-muted">一头酸奶牛_</span> <a class="tag" taget="_blank" href="/search/%E5%B7%A5%E5%85%B7%E7%B1%BB/1.htm">工具类</a><a class="tag" taget="_blank" href="/search/java/1.htm">java</a> <div>文章目录第一步:准备文件第二步:将word文件另存为.xml格式第三步:放到idea中的一个目录下第四步:修改占位符第五步:代码示例第六步:效果图1第六步:效果图2第一步:准备文件这里以这个文件为例,在要替换的地方用占位符$replaceXX@替换。第二步:将word文件另存为.xml格式第三步:放到idea中的一个目录下这里已src目录为例第四步:修改占位符第五步:代码示例packagecom.</div> </li> <li><a href="/article/31.htm" title="312个免费高速HTTP代理IP(能隐藏自己真实IP地址)" target="_blank">312个免费高速HTTP代理IP(能隐藏自己真实IP地址)</a> <span class="text-muted">yangshangchuan</span> <a class="tag" taget="_blank" href="/search/%E9%AB%98%E9%80%9F/1.htm">高速</a><a class="tag" taget="_blank" href="/search/%E5%85%8D%E8%B4%B9/1.htm">免费</a><a class="tag" taget="_blank" href="/search/superword/1.htm">superword</a><a class="tag" taget="_blank" href="/search/HTTP%E4%BB%A3%E7%90%86/1.htm">HTTP代理</a> <div>    124.88.67.20:843 190.36.223.93:8080 117.147.221.38:8123 122.228.92.103:3128 183.247.211.159:8123 124.88.67.35:81 112.18.51.167:8123 218.28.96.39:3128 49.94.160.198:3128 183.20</div> </li> <li><a href="/article/158.htm" title="pull解析和json编码" target="_blank">pull解析和json编码</a> <span class="text-muted">百合不是茶</span> <a class="tag" taget="_blank" href="/search/android/1.htm">android</a><a class="tag" taget="_blank" href="/search/pull%E8%A7%A3%E6%9E%90/1.htm">pull解析</a><a class="tag" taget="_blank" href="/search/json/1.htm">json</a> <div>n.json文件: [{name:java,lan:c++,age:17},{name:android,lan:java,age:8}]   pull.xml文件 <?xml version="1.0" encoding="utf-8"?> <stu>     <name>java</div> </li> <li><a href="/article/285.htm" title="[能源与矿产]石油与地球生态系统" target="_blank">[能源与矿产]石油与地球生态系统</a> <span class="text-muted">comsci</span> <a class="tag" taget="_blank" href="/search/%E8%83%BD%E6%BA%90/1.htm">能源</a> <div>       按照苏联的科学界的说法,石油并非是远古的生物残骸的演变产物,而是一种可以由某些特殊地质结构和物理条件生产出来的东西,也就是说,石油是可以自增长的....       那么我们做一个猜想: 石油好像是地球的体液,我们地球具有自动产生石油的某种机制,只要我们不过量开采石油,并保护好</div> </li> <li><a href="/article/412.htm" title="类与对象浅谈" target="_blank">类与对象浅谈</a> <span class="text-muted">沐刃青蛟</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/%E5%9F%BA%E7%A1%80/1.htm">基础</a> <div>        类,字面理解,便是同一种事物的总称,比如人类,是对世界上所有人的一个总称。而对象,便是类的具体化,实例化,是一个具体事物,比如张飞这个人,就是人类的一个对象。但要注意的是:张飞这个人是对象,而不是张飞,张飞只是他这个人的名字,是他的属性而已。而一个类中包含了属性和方法这两兄弟,他们分别用来描述对象的行为和性质(感觉应该是</div> </li> <li><a href="/article/539.htm" title="新站开始被收录后,我们应该做什么?" target="_blank">新站开始被收录后,我们应该做什么?</a> <span class="text-muted">IT独行者</span> <a class="tag" taget="_blank" href="/search/PHP/1.htm">PHP</a><a class="tag" taget="_blank" href="/search/seo/1.htm">seo</a> <div>新站开始被收录后,我们应该做什么?         百度终于开始收录自己的网站了,作为站长,你是不是觉得那一刻很有成就感呢,同时,你是不是又很茫然,不知道下一步该做什么了?至少我当初就是这样,在这里和大家一份分享一下新站收录后,我们要做哪些工作。       至于如何让百度快速收录自己的网站,可以参考我之前的帖子《新站让百</div> </li> <li><a href="/article/666.htm" title="oracle 连接碰到的问题" target="_blank">oracle 连接碰到的问题</a> <span class="text-muted">文强chu</span> <a class="tag" taget="_blank" href="/search/oracle/1.htm">oracle</a> <div>Unable to find a java Virtual Machine--安装64位版Oracle11gR2后无法启动SQLDeveloper的解决方案 作者:草根IT网 来源:未知 人气:813标签: 导读:安装64位版Oracle11gR2后发现启动SQLDeveloper时弹出配置java.exe的路径,找到Oracle自带java.exe后产生的路径“C:\app\用户名\prod</div> </li> <li><a href="/article/793.htm" title="Swing中按ctrl键同时移动鼠标拖动组件(类中多借口共享同一数据)" target="_blank">Swing中按ctrl键同时移动鼠标拖动组件(类中多借口共享同一数据)</a> <span class="text-muted">小桔子</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/%E7%BB%A7%E6%89%BF/1.htm">继承</a><a class="tag" taget="_blank" href="/search/swing/1.htm">swing</a><a class="tag" taget="_blank" href="/search/%E6%8E%A5%E5%8F%A3/1.htm">接口</a><a class="tag" taget="_blank" href="/search/%E7%9B%91%E5%90%AC/1.htm">监听</a> <div>        都知道java中类只能单继承,但可以实现多个接口,但我发现实现多个接口之后,多个接口却不能共享同一个数据,应用开发中想实现:当用户按着ctrl键时,可以用鼠标点击拖动组件,比如说文本框。 编写一个监听实现KeyListener,NouseListener,MouseMotionListener三个接口,重写方法。定义一个全局变量boolea</div> </li> <li><a href="/article/920.htm" title="linux常用的命令" target="_blank">linux常用的命令</a> <span class="text-muted">aichenglong</span> <a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a><a class="tag" taget="_blank" href="/search/%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/1.htm">常用命令</a> <div>1 startx切换到图形化界面 2 man命令:查看帮助信息 man 需要查看的命令,man命令提供了大量的帮助信息,一般可以分成4个部分 name:对命令的简单说明 synopsis:命令的使用格式说明 description:命令的详细说明信息 options:命令的各项说明 3 date:显示时间 语法:date [OPTION]... [+FORMAT] </div> </li> <li><a href="/article/1047.htm" title="eclipse内存优化" target="_blank">eclipse内存优化</a> <span class="text-muted">AILIKES</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/eclipse/1.htm">eclipse</a><a class="tag" taget="_blank" href="/search/jvm/1.htm">jvm</a><a class="tag" taget="_blank" href="/search/jdk/1.htm">jdk</a> <div>一 基本说明      在JVM中,总体上分2块内存区,默认空余堆内存小于 40%时,JVM就会增大堆直到-Xmx的最大限制;空余堆内存大于70%时,JVM会减少堆直到-Xms的最小限制。     1)堆内存(Heap memory):堆是运行时数据区域,所有类实例和数组的内存均从此处分配,是Java代码可及的内存,是留给开发人</div> </li> <li><a href="/article/1174.htm" title="关键字的使用探讨" target="_blank">关键字的使用探讨</a> <span class="text-muted">百合不是茶</span> <a class="tag" taget="_blank" href="/search/%E5%85%B3%E9%94%AE%E5%AD%97/1.htm">关键字</a> <div>//关键字的使用探讨/*访问关键词private 只能在本类中访问public 只能在本工程中访问protected 只能在包中和子类中访问默认的 只能在包中访问*//*final   类 方法 变量 final 类 不能被继承 final 方法 不能被子类覆盖,但可以继承 final 变量 只能有一次赋值,赋值后不能改变 final 不能用来修饰构造方法*///this()</div> </li> <li><a href="/article/1301.htm" title="JS中定义对象的几种方式" target="_blank">JS中定义对象的几种方式</a> <span class="text-muted">bijian1013</span> <a class="tag" taget="_blank" href="/search/js/1.htm">js</a> <div>    1. 基于已有对象扩充其对象和方法(只适合于临时的生成一个对象): <html> <head> <title>基于已有对象扩充其对象和方法(只适合于临时的生成一个对象)</title> </head> <script> var obj = new Object(); </div> </li> <li><a href="/article/1428.htm" title="表驱动法实例" target="_blank">表驱动法实例</a> <span class="text-muted">bijian1013</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/%E8%A1%A8%E9%A9%B1%E5%8A%A8%E6%B3%95/1.htm">表驱动法</a><a class="tag" taget="_blank" href="/search/TDD/1.htm">TDD</a> <div>获得月的天数是典型的直接访问驱动表方式的实例,下面我们来展示一下: MonthDaysTest.java package com.study.test; import org.junit.Assert; import org.junit.Test; import com.study.MonthDays; public class MonthDaysTest { @T</div> </li> <li><a href="/article/1555.htm" title="LInux启停重启常用服务器的脚本" target="_blank">LInux启停重启常用服务器的脚本</a> <span class="text-muted">bit1129</span> <a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a> <div>启动,停止和重启常用服务器的Bash脚本,对于每个服务器,需要根据实际的安装路径做相应的修改   #! /bin/bash Servers=(Apache2, Nginx, Resin, Tomcat, Couchbase, SVN, ActiveMQ, Mongo); Ops=(Start, Stop, Restart); currentDir=$(pwd); echo</div> </li> <li><a href="/article/1682.htm" title="【HBase六】REST操作HBase" target="_blank">【HBase六】REST操作HBase</a> <span class="text-muted">bit1129</span> <a class="tag" taget="_blank" href="/search/hbase/1.htm">hbase</a> <div>HBase提供了REST风格的服务方便查看HBase集群的信息,以及执行增删改查操作   1. 启动和停止HBase REST 服务 1.1 启动REST服务 前台启动(默认端口号8080) [hadoop@hadoop bin]$ ./hbase rest start   后台启动 hbase-daemon.sh start rest   启动时指定</div> </li> <li><a href="/article/1809.htm" title="大话zabbix 3.0设计假设" target="_blank">大话zabbix 3.0设计假设</a> <span class="text-muted">ronin47</span> <div>What’s new in Zabbix 2.0? 去年开始使用Zabbix的时候,是1.8.X的版本,今年Zabbix已经跨入了2.0的时代。看了2.0的release notes,和performance相关的有下面几个:          :: Performance improvements::Trigger related da</div> </li> <li><a href="/article/1936.htm" title="http错误码大全" target="_blank">http错误码大全</a> <span class="text-muted">byalias</span> <a class="tag" taget="_blank" href="/search/http%E5%8D%8F%E8%AE%AE/1.htm">http协议</a><a class="tag" taget="_blank" href="/search/javaweb/1.htm">javaweb</a> <div>响应码由三位十进制数字组成,它们出现在由HTTP服务器发送的响应的第一行。 响应码分五种类型,由它们的第一位数字表示: 1)1xx:信息,请求收到,继续处理 2)2xx:成功,行为被成功地接受、理解和采纳 3)3xx:重定向,为了完成请求,必须进一步执行的动作 4)4xx:客户端错误,请求包含语法错误或者请求无法实现 5)5xx:服务器错误,服务器不能实现一种明显无效的请求 </div> </li> <li><a href="/article/2063.htm" title="J2EE设计模式-Intercepting Filter" target="_blank">J2EE设计模式-Intercepting Filter</a> <span class="text-muted">bylijinnan</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/1.htm">设计模式</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/1.htm">数据结构</a> <div>Intercepting Filter类似于职责链模式 有两种实现 其中一种是Filter之间没有联系,全部Filter都存放在FilterChain中,由FilterChain来有序或无序地把把所有Filter调用一遍。没有用到链表这种数据结构。示例如下: package com.ljn.filter.custom; import java.util.ArrayList;</div> </li> <li><a href="/article/2190.htm" title="修改jboss端口" target="_blank">修改jboss端口</a> <span class="text-muted">chicony</span> <a class="tag" taget="_blank" href="/search/jboss/1.htm">jboss</a> <div>修改jboss端口   %JBOSS_HOME%\server\{服务实例名}\conf\bindingservice.beans\META-INF\bindings-jboss-beans.xml   中找到 <!-- The ports-default bindings are obtained by taking the base bindin</div> </li> <li><a href="/article/2317.htm" title="c++ 用类模版实现数组类" target="_blank">c++ 用类模版实现数组类</a> <span class="text-muted">CrazyMizzz</span> <a class="tag" taget="_blank" href="/search/C%2B%2B/1.htm">C++</a> <div>最近c++学到数组类,写了代码将他实现,基本具有vector类的功能 #include<iostream> #include<string> #include<cassert> using namespace std; template<class T> class Array { public: //构造函数 </div> </li> <li><a href="/article/2444.htm" title="hadoop dfs.datanode.du.reserved 预留空间配置方法" target="_blank">hadoop dfs.datanode.du.reserved 预留空间配置方法</a> <span class="text-muted">daizj</span> <a class="tag" taget="_blank" href="/search/hadoop/1.htm">hadoop</a><a class="tag" taget="_blank" href="/search/%E9%A2%84%E7%95%99%E7%A9%BA%E9%97%B4/1.htm">预留空间</a> <div>对于datanode配置预留空间的方法 为:在hdfs-site.xml添加如下配置  <property>     <name>dfs.datanode.du.reserved</name>     <value>10737418240</value>    </div> </li> <li><a href="/article/2571.htm" title="mysql远程访问的设置" target="_blank">mysql远程访问的设置</a> <span class="text-muted">dcj3sjt126com</span> <a class="tag" taget="_blank" href="/search/mysql/1.htm">mysql</a><a class="tag" taget="_blank" href="/search/%E9%98%B2%E7%81%AB%E5%A2%99/1.htm">防火墙</a> <div>第一步: 激活网络设置 你需要编辑mysql配置文件my.cnf. 通常状况,my.cnf放置于在以下目录: /etc/mysql/my.cnf (Debian linux) /etc/my.cnf (Red Hat Linux/Fedora Linux) /var/db/mysql/my.cnf (FreeBSD) 然后用vi编辑my.cnf,修改内容从以下行: [mysqld] 你所需要: 1</div> </li> <li><a href="/article/2698.htm" title="ios 使用特定的popToViewController返回到相应的Controller" target="_blank">ios 使用特定的popToViewController返回到相应的Controller</a> <span class="text-muted">dcj3sjt126com</span> <a class="tag" taget="_blank" href="/search/controller/1.htm">controller</a> <div>1、取navigationCtroller中的Controllers NSArray * ctrlArray = self.navigationController.viewControllers; 2、取出后,执行, [self.navigationController popToViewController:[ctrlArray objectAtIndex:0] animated:YES</div> </li> <li><a href="/article/2825.htm" title="Linux正则表达式和通配符的区别" target="_blank">Linux正则表达式和通配符的区别</a> <span class="text-muted">eksliang</span> <a class="tag" taget="_blank" href="/search/%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F/1.htm">正则表达式</a><a class="tag" taget="_blank" href="/search/%E9%80%9A%E9%85%8D%E7%AC%A6%E5%92%8C%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%E7%9A%84%E5%8C%BA%E5%88%AB/1.htm">通配符和正则表达式的区别</a><a class="tag" taget="_blank" href="/search/%E9%80%9A%E9%85%8D%E7%AC%A6/1.htm">通配符</a> <div>转载请出自出处:http://eksliang.iteye.com/blog/1976579 首先得明白二者是截然不同的 通配符只能用在shell命令中,用来处理字符串的的匹配。 判断一个命令是否为bash shell(linux 默认的shell)的内置命令 type -t commad 返回结果含义 file  表示为外部命令 alias  表示该</div> </li> <li><a href="/article/2952.htm" title="Ubuntu Mysql Install and CONF" target="_blank">Ubuntu Mysql Install and CONF</a> <span class="text-muted">gengzg</span> <a class="tag" taget="_blank" href="/search/Install/1.htm">Install</a> <div>http://www.navicat.com.cn/download/navicat-for-mysql Step1: 下载Navicat ,网址:http://www.navicat.com/en/download/download.html Step2:进入下载目录,解压压缩包:tar -zxvf navicat11_mysql_en.tar.gz </div> </li> <li><a href="/article/3079.htm" title="批处理,删除文件bat" target="_blank">批处理,删除文件bat</a> <span class="text-muted">huqiji</span> <a class="tag" taget="_blank" href="/search/windows/1.htm">windows</a><a class="tag" taget="_blank" href="/search/dos/1.htm">dos</a> <div>@echo off ::演示:删除指定路径下指定天数之前(以文件名中包含的日期字符串为准)的文件。 ::如果演示结果无误,把del前面的echo去掉,即可实现真正删除。 ::本例假设文件名中包含的日期字符串(比如:bak-2009-12-25.log) rem 指定待删除文件的存放路径 set SrcDir=C:/Test/BatHome rem 指定天数 set DaysAgo=1</div> </li> <li><a href="/article/3206.htm" title="跨浏览器兼容的HTML5视频音频播放器" target="_blank">跨浏览器兼容的HTML5视频音频播放器</a> <span class="text-muted">天梯梦</span> <a class="tag" taget="_blank" href="/search/html5/1.htm">html5</a> <div>HTML5的video和audio标签是用来在网页中加入视频和音频的标签,在支持html5的浏览器中不需要预先加载Adobe Flash浏览器插件就能轻松快速的播放视频和音频文件。而html5media.js可以在不支持html5的浏览器上使video和audio标签生效。   How to enable <video> and <audio> tags in </div> </li> <li><a href="/article/3333.htm" title="Bundle自定义数据传递" target="_blank">Bundle自定义数据传递</a> <span class="text-muted">hm4123660</span> <a class="tag" taget="_blank" href="/search/android/1.htm">android</a><a class="tag" taget="_blank" href="/search/Serializable/1.htm">Serializable</a><a class="tag" taget="_blank" href="/search/%E8%87%AA%E5%AE%9A%E4%B9%89%E6%95%B0%E6%8D%AE%E4%BC%A0%E9%80%92/1.htm">自定义数据传递</a><a class="tag" taget="_blank" href="/search/Bundle/1.htm">Bundle</a><a class="tag" taget="_blank" href="/search/Parcelable/1.htm">Parcelable</a> <div>      我们都知道Bundle可能过put****()方法添加各种基本类型的数据,Intent也可以通过putExtras(Bundle)将数据添加进去,然后通过startActivity()跳到下一下Activity的时候就把数据也传到下一个Activity了。如传递一个字符串到下一个Activity   把数据放到Intent</div> </li> <li><a href="/article/3460.htm" title="C#:异步编程和线程的使用(.NET 4.5 )" target="_blank">C#:异步编程和线程的使用(.NET 4.5 )</a> <span class="text-muted">powertoolsteam</span> <a class="tag" taget="_blank" href="/search/.net/1.htm">.net</a><a class="tag" taget="_blank" href="/search/%E7%BA%BF%E7%A8%8B/1.htm">线程</a><a class="tag" taget="_blank" href="/search/C%23/1.htm">C#</a><a class="tag" taget="_blank" href="/search/%E5%BC%82%E6%AD%A5%E7%BC%96%E7%A8%8B/1.htm">异步编程</a> <div>异步编程和线程处理是并发或并行编程非常重要的功能特征。为了实现异步编程,可使用线程也可以不用。将异步与线程同时讲,将有助于我们更好的理解它们的特征。 本文中涉及关键知识点 1. 异步编程 2. 线程的使用 3. 基于任务的异步模式 4. 并行编程 5. 总结 异步编程 什么是异步操作?异步操作是指某些操作能够独立运行,不依赖主流程或主其他处理流程。通常情况下,C#程序</div> </li> <li><a href="/article/3587.htm" title="spark 查看 job history 日志" target="_blank">spark 查看 job history 日志</a> <span class="text-muted">Stark_Summer</span> <a class="tag" taget="_blank" href="/search/%E6%97%A5%E5%BF%97/1.htm">日志</a><a class="tag" taget="_blank" href="/search/spark/1.htm">spark</a><a class="tag" taget="_blank" href="/search/history/1.htm">history</a><a class="tag" taget="_blank" href="/search/job/1.htm">job</a> <div>SPARK_HOME/conf 下: spark-defaults.conf 增加如下内容 spark.eventLog.enabled true spark.eventLog.dir hdfs://master:8020/var/log/spark spark.eventLog.compress true spark-env.sh 增加如下内容 export SP</div> </li> <li><a href="/article/3714.htm" title="SSH框架搭建" target="_blank">SSH框架搭建</a> <span class="text-muted">wangxiukai2015eye</span> <a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a><a class="tag" taget="_blank" href="/search/Hibernate/1.htm">Hibernate</a><a class="tag" taget="_blank" href="/search/struts/1.htm">struts</a> <div>MyEclipse搭建SSH框架 Struts Spring Hibernate 1、new一个web project。 2、右键项目,为项目添加Struts支持。    选择Struts2 Core Libraries -<MyEclipes-Library>      点击Finish。src目录下多了struts</div> </li> </ul> </div> </div> </div> <div> <div class="container"> <div class="indexes"> <strong>按字母分类:</strong> <a href="/tags/A/1.htm" target="_blank">A</a><a href="/tags/B/1.htm" target="_blank">B</a><a href="/tags/C/1.htm" target="_blank">C</a><a href="/tags/D/1.htm" target="_blank">D</a><a href="/tags/E/1.htm" target="_blank">E</a><a href="/tags/F/1.htm" target="_blank">F</a><a href="/tags/G/1.htm" target="_blank">G</a><a href="/tags/H/1.htm" target="_blank">H</a><a href="/tags/I/1.htm" target="_blank">I</a><a href="/tags/J/1.htm" target="_blank">J</a><a href="/tags/K/1.htm" target="_blank">K</a><a href="/tags/L/1.htm" target="_blank">L</a><a href="/tags/M/1.htm" target="_blank">M</a><a href="/tags/N/1.htm" target="_blank">N</a><a href="/tags/O/1.htm" target="_blank">O</a><a href="/tags/P/1.htm" target="_blank">P</a><a href="/tags/Q/1.htm" target="_blank">Q</a><a href="/tags/R/1.htm" target="_blank">R</a><a href="/tags/S/1.htm" target="_blank">S</a><a href="/tags/T/1.htm" target="_blank">T</a><a href="/tags/U/1.htm" target="_blank">U</a><a href="/tags/V/1.htm" target="_blank">V</a><a href="/tags/W/1.htm" target="_blank">W</a><a href="/tags/X/1.htm" target="_blank">X</a><a href="/tags/Y/1.htm" target="_blank">Y</a><a href="/tags/Z/1.htm" target="_blank">Z</a><a href="/tags/0/1.htm" target="_blank">其他</a> </div> </div> </div> <footer id="footer" class="mb30 mt30"> <div class="container"> <div class="footBglm"> <a target="_blank" href="/">首页</a> - <a target="_blank" href="/custom/about.htm">关于我们</a> - <a target="_blank" href="/search/Java/1.htm">站内搜索</a> - <a target="_blank" href="/sitemap.txt">Sitemap</a> - <a target="_blank" href="/custom/delete.htm">侵权投诉</a> </div> <div class="copyright">版权所有 IT知识库 CopyRight © 2000-2050 E-COM-NET.COM , All Rights Reserved. <!-- <a href="https://beian.miit.gov.cn/" rel="nofollow" target="_blank">京ICP备09083238号</a><br>--> </div> </div> </footer> <!-- 代码高亮 --> <script type="text/javascript" src="/static/syntaxhighlighter/scripts/shCore.js"></script> <script type="text/javascript" src="/static/syntaxhighlighter/scripts/shLegacy.js"></script> <script type="text/javascript" src="/static/syntaxhighlighter/scripts/shAutoloader.js"></script> <link type="text/css" rel="stylesheet" href="/static/syntaxhighlighter/styles/shCoreDefault.css"/> <script type="text/javascript" src="/static/syntaxhighlighter/src/my_start_1.js"></script> </body> </html>