aboutsummaryrefslogtreecommitdiff
path: root/files/ja/web/api/document/evaluate
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/ja/web/api/document/evaluate
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/ja/web/api/document/evaluate')
-rw-r--r--files/ja/web/api/document/evaluate/index.html209
1 files changed, 209 insertions, 0 deletions
diff --git a/files/ja/web/api/document/evaluate/index.html b/files/ja/web/api/document/evaluate/index.html
new file mode 100644
index 0000000000..6ca3c32fff
--- /dev/null
+++ b/files/ja/web/api/document/evaluate/index.html
@@ -0,0 +1,209 @@
+---
+title: Document.evaluate()
+slug: Web/API/Document/evaluate
+translation_of: Web/API/Document/evaluate
+---
+<div>{{ ApiRef("DOM") }}</div>
+
+<div><a href="/en-US/docs/XPath" title="XPath">XPath</a> 式やその他与えられたパラメータに基づいて <code><a href="/en-US/docs/XPathResult" title="XPathResult">XPathResult</a></code> を返します。</div>
+
+<div> </div>
+
+<h2 id="Syntax" name="Syntax">構文</h2>
+
+<pre class="syntaxbox">var xpathResult = document.evaluate(
+ xpathExpression,
+ contextNode,
+ namespaceResolver,
+ resultType,
+ result
+);</pre>
+
+<ul>
+ <li><code>xpathExpression</code> は評価される Xpath を示す文字列です。</li>
+ <li><code>contextNode</code> はクエリの<em>コンテキストノード</em>を指定します(<a href="http://www.w3.org/TR/xpath" rel="freelink">XPath の仕様</a>を参照してください) コンテキストノードとして <code>document</code> を渡すのが一般的です。</li>
+ <li><code>namespaceResolver</code> は、任意の名前空間接頭辞を受け取り、その接頭辞に関連付けられた名前空間 URI を文字列として返す関数です。接頭辞が文書の中でマッチされるように、XPath 自身の中で接頭辞を解決するために使われます。HTML 文書向け、または名前空間接頭辞を使わないときは <code>null</code> を指定するのが一般的です。</li>
+ <li><code>resultType</code> は返り値である <code>XPathResult</code> のタイプに対応する整数です。XPathResult コンストラクタの<a href="#Result_types">名前付き定数プロパティ</a> (例えば <code>XPathResult.ANY_TYPE</code>) を使用してください。これらは0から9までの整数に対応しています。</li>
+ <li><code>result</code> は結果として使われる既存の <code>XPathResult</code> です。<code>null</code> を指定するのが最も一般的です。<code>null</code> は新しい <code>XPathResult を生成します。</code></li>
+</ul>
+
+<h2 id="Example" name="Example">例</h2>
+
+<pre class="brush: js">var headings = document.evaluate("/html/body//h2", document, null, XPathResult.ANY_TYPE, null);
+/* Search the document for all h2 elements.
+ * The result will likely be an unordered node iterator. */
+var thisHeading = headings.iterateNext();
+var alertText = "Level 2 headings in this document are:\n";
+while (thisHeading) {
+ alertText += thisHeading.textContent + "\n";
+ thisHeading = headings.iterateNext();
+}
+alert(alertText); // Alerts the text of all h2 elements
+</pre>
+
+<p>Note, in the above example, a more verbose XPath is preferred over common shortcuts such as <code>//h2</code>. Generally, more specific XPath selectors as in the above example usually gives a significant performance improvement, especially on very large documents. This is because the evaluation of the query spends does not waste time visiting unnecessary nodes. Using // is generally slow as it visits <em>every</em> node from the root and all subnodes looking for possible matches.</p>
+
+<p>Further optimization can be achieved by careful use of the context parameter. For example, if you know the content you are looking for is somewhere inside the body tag, you can use this:</p>
+
+<pre class="brush: js">document.evaluate(".//h2", document.body, null, XPathResult.ANY_TYPE, null);
+</pre>
+
+<p>Notice in the above <code>document.body</code> has been used as the context instead of <code>document</code> so the XPath starts from the body element. (In this example, the <code>"."</code> is important to indicate that the querying should start from the context node, document.body. If the "." was left out (leaving <code>//h2</code>) the query would start from the root node (<code>html</code>) which would be more wasteful.)</p>
+
+<p>See <a href="/en-US/docs/Introduction_to_using_XPath_in_JavaScript" title="Introduction to using XPath in JavaScript">Introduction to using XPath in JavaScript</a> for more information.</p>
+
+<h2 id="Notes" name="Notes">注釈</h2>
+
+<ul>
+ <li>XPath expressions can be evaluated on HTML and XML documents.</li>
+ <li>While using document.evaluate() works in FF2, in FF3 one must use someXMLDoc.evaluate() if evaluating against something other than the current document.</li>
+</ul>
+
+<h2 id="Result_types" name="Result_types">戻り値の分類</h2>
+
+<p>(Merge with <a href="/Template:XPathResultConstants" title="Template:XPathResultConstants">Template:XPathResultConstants</a>?</p>
+
+<p>These are supported values for the <code>resultType</code> parameter of the <code>evaluate</code> method:</p>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <td class="header">Result Type</td>
+ <td class="header">Value</td>
+ <td class="header">Description</td>
+ </tr>
+ <tr>
+ <td><code>ANY_TYPE</code></td>
+ <td>0</td>
+ <td>Whatever type naturally results from the given expression.</td>
+ </tr>
+ <tr>
+ <td><code>NUMBER_TYPE</code></td>
+ <td>1</td>
+ <td>A result set containing a single number. Useful, for example, in an XPath expression using the <code>count()</code> function.</td>
+ </tr>
+ <tr>
+ <td><code>STRING_TYPE</code></td>
+ <td>2</td>
+ <td>A result set containing a single string.</td>
+ </tr>
+ <tr>
+ <td><code>BOOLEAN_TYPE</code></td>
+ <td>3</td>
+ <td>A result set containing a single boolean value. Useful, for example, an an XPath expression using the <code>not()</code> function.</td>
+ </tr>
+ <tr>
+ <td><code>UNORDERED_NODE_ITERATOR_TYPE</code></td>
+ <td>4</td>
+ <td>A result set containing all the nodes matching the expression. The nodes in the result set are not necessarily in the same order they appear in the document.</td>
+ </tr>
+ <tr>
+ <td><code>ORDERED_NODE_ITERATOR_TYPE</code></td>
+ <td>5</td>
+ <td>A result set containing all the nodes matching the expression. The nodes in the result set are in the same order they appear in the document.</td>
+ </tr>
+ <tr>
+ <td><code>UNORDERED_NODE_SNAPSHOT_TYPE</code></td>
+ <td>6</td>
+ <td>A result set containing snapshots of all the nodes matching the expression. The nodes in the result set are not necessarily in the same order they appear in the document.</td>
+ </tr>
+ <tr>
+ <td><code>ORDERED_NODE_SNAPSHOT_TYPE</code></td>
+ <td>7</td>
+ <td>A result set containing snapshots of all the nodes matching the expression. The nodes in the result set are in the same order they appear in the document.</td>
+ </tr>
+ <tr>
+ <td><code>ANY_UNORDERED_NODE_TYPE</code></td>
+ <td>8</td>
+ <td>A result set containing any single node that matches the expression. The node is not necessarily the first node in the document that matches the expression.</td>
+ </tr>
+ <tr>
+ <td><code>FIRST_ORDERED_NODE_TYPE</code></td>
+ <td>9</td>
+ <td>A result set containing the first node in the document that matches the expression.</td>
+ </tr>
+ </tbody>
+</table>
+
+<p>Results of <code>NODE_ITERATOR</code> types contain references to nodes in the document. Modifying a node will invalidate the iterator. After modifying a node, attempting to iterate through the results will result in an error.</p>
+
+<p>Results of <code>NODE_SNAPSHOT</code> types are snapshots, which are essentially lists of matched nodes. You can make changes to the document by altering snapshot nodes. Modifying the document doesn't invalidate the snapshot; however, if the document is changed, the snapshot may not correspond to the current state of the document, since nodes may have moved, been changed, added, or removed.</p>
+
+<h2 id="Specifications" name="Specifications">仕様</h2>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{SpecName("DOM3 XPath", "xpath.html#XPathEvaluator-evaluate", "Document.evaluate")}}</td>
+ <td>{{Spec2("DOM3 XPath")}}</td>
+ <td>Initial specification</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザ互換性</h2>
+
+<p>{{CompatibilityTable}}</p>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Chrome</th>
+ <th>Firefox (Gecko)</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari (WebKit)</th>
+ </tr>
+ <tr>
+ <td>XPath 1.0 support</td>
+ <td>1</td>
+ <td>1.5 (1.8)</td>
+ <td>{{CompatNo}}</td>
+ <td>9.0</td>
+ <td>{{CompatVersionUnknown}}<sup>[1]</sup></td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Android</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>IE Mobile</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ </tr>
+ <tr>
+ <td>XPath 1.0</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<p>[1] Implemented in WebKit 5.0 (531) or earlier.</p>
+
+<h2 id="See_also" name="See_also">関連項目</h2>
+
+<ul>
+ <li><a href="/en-US/docs/DOM/document.createExpression" title="DOM/document.createExpression">DOM:document.createExpression</a></li>
+ <li><a href="/en-US/docs/Code_snippets/XPath" title="Code_snippets/XPath">XPath Code Snippets</a></li>
+ <li><a href="http://codepen.io/johan/full/ckFgn">Check for browser support</a></li>
+</ul>