<s1 title="XPath select()">

<p>Finding a node is useful but often you will want to select all nodes
matching a pattern.  For example, a web spider will want to select all links
in a HTML page.</p>

<p>The <var/select()/> call returns an Iterator letting you look at all
the nodes.  The Iterator returns nodes in document order.</p>

<p>You can precompile XPath patterns and then reuse the precompiled pattern
over again.  The <var/XPath.find()/> call in the previous page used a
convenient, but inefficient call to find the node.  In this example, we'll
precompile the pattern before using the select.</p>

<p>The following example reads the home page of http://localhost:8080 and
and returns all the &lt;a href> links in that page.</p>

<example title="Spidering a Web Page">
Pattern pattern = XPath.parseMatch("a[@href]");

Document doc = new Html().parseDocument("http://localhost:8080");

Iterator iter = pattern.select(doc);

while (iter.hasNext()) {
  Element elt = (Element) iter.next();

  System.out.println("link: " + elt.getAttribute("href"));
}
</example>
<results>
link: /index.xtp
link: /ref/faq.xtp
link: /ref/index.xtp
link: /javadoc/index.html

...
</results>

<s2 title="Summary">

<ul>
<li>Precompiling <var/XPath/> patterns is more efficient
<li><var/XPath.select()/> can "spider" web pages
<li>select returns nodes in <var/document order/>
<li>The pattern <var/a[@href]/> returns <var/&lt;a>/> elements
with an <var/href/> attribute.
</ul>

</s2>
</s1>
