aboutsummaryrefslogtreecommitdiff
path: root/files/de/web/xpath
diff options
context:
space:
mode:
authorFlorian Merz <me@fiji-flo.de>2021-02-11 14:45:38 +0100
committerFlorian Merz <me@fiji-flo.de>2021-02-11 14:45:38 +0100
commit4ab365b110f2f1f2b736326b7059244a32115089 (patch)
treec3c7c0219f728ade49a78c238c51cc0c8d06ebd6 /files/de/web/xpath
parent8260a606c143e6b55a467edf017a56bdcd6cba7e (diff)
downloadtranslated-content-4ab365b110f2f1f2b736326b7059244a32115089.tar.gz
translated-content-4ab365b110f2f1f2b736326b7059244a32115089.tar.bz2
translated-content-4ab365b110f2f1f2b736326b7059244a32115089.zip
unslug de: move
Diffstat (limited to 'files/de/web/xpath')
-rw-r--r--files/de/web/xpath/introduction_to_using_xpath_in_javascript/index.html411
1 files changed, 411 insertions, 0 deletions
diff --git a/files/de/web/xpath/introduction_to_using_xpath_in_javascript/index.html b/files/de/web/xpath/introduction_to_using_xpath_in_javascript/index.html
new file mode 100644
index 0000000000..6af0ba9e0e
--- /dev/null
+++ b/files/de/web/xpath/introduction_to_using_xpath_in_javascript/index.html
@@ -0,0 +1,411 @@
+---
+title: Einführung in den Gebrauch von XPath in JavaScript
+slug: Web/JavaScript/Einführung_in_den_Gebrauch_von_XPath_in_JavaScript
+translation_of: Web/XPath/Introduction_to_using_XPath_in_JavaScript
+---
+<p>Dieses Dokument beschreibt die Schnittstelle zu <a href="/en-US/docs/XPath" title="en/XPath">XPath</a> in JavaScript intern, in Erweiterungen und in Webseiten. Mozilla implementiert einen großen Teil von <a class="external" href="http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html">DOM 3 XPath</a>, sodass XPath auf HTML- und XML-Dokumente angewendet werden kann.</p>
+
+<p>Die Hauptschnittstelle für die Anwendung von XPath ist die <a href="/en-US/docs/Web/API/document.evaluate" title="en/DOM/document.evaluate">evaluate</a>-Methode des <a href="/en-US/Web/API/document" title="en/DOM/document">document</a>-Objekts.</p>
+
+<h2 id="document.evaluate" name="document.evaluate">document.evaluate</h2>
+
+<p>Diese Methode wertet  <a href="/en-US/docs/XPath" title="en/XPath">XPath</a> Ausdrücke in Bezug auf ein <a href="/en-US/docs/Glossary/XML" title="en/XML">XML</a> basierendes Dokument (einschließlich HTML-Documente) aus und gibt ein <code><a href="/en-US/docs/XPathResult" title="en/XPathResult">XPathResult</a></code>-Objekt zurück, das ein Einzelknoten oder eine Zusammenstellung mehrerer Knoten sein kann. Die vorhandene Dokumentation dieser Methode ist unter <a href="/en-US/docs/Web/API/Document.evaluate" title="en/DOM/document.evaluate">document.evaluate</a> zu finden, sie ist jedoch für unseren jetzigen Bedarf ziemlich knapp gehalten. Eine umfangreichere Betrachtung wird nachfolgend beschrieben.</p>
+
+<pre class="brush: js">var xpathResult = document.evaluate( xpathExpression, contextNode, namespaceResolver, resultType, result );
+</pre>
+
+<h3 id="Parameters" name="Parameters">Parameter</h3>
+
+<p>Die <a href="/en-US/docs/Web/API/Document.evaluate" title="en/DOM/document.evaluate">evaluate</a> Funktion nimmt insgesamt fünf Parameter entgegen:</p>
+
+<ul>
+ <li><code>xpathExpression</code>: Eine Zeichenkette, die den auszuwertenden XPath-Ausdrucks beinhaltet.</li>
+ <li><code>contextNode</code>: Ein Bezugsknoten im Dokument, auf den sich die Auswertung von <code>xpathExpression</code> beziehen soll, einschließlich sämtlicher Kindknoten. Am häufigsten wird hierfür der <a href="/en-US/docs/Web/API/document" title="en/DOM/document">document</a>-Knoten verwendet.</li>
+ <li><code>namespaceResolver</code>: A function that will be passed any namespace prefixes contained within <code>xpathExpression</code> which returns a string representing the namespace URI associated with that prefix. This enables conversion between the prefixes used in the XPath expressions and the possibly different prefixes used in the document. The function can be either:
+ <ul>
+ <li><a href="#Implementing_a_Default_Namespace_Resolver">Created</a> by using the <code><a href="/en-US/docs/Web/API/Document.createNSResolver" title="en/DOM/document.createNSResolver">createNSResolver</a></code> method of a <code><a href="/en-US/docs/Using_XPath#Node-specific_evaluator_function" title="en/XPathEvaluator">XPathEvaluator</a></code> object. You should use this virtually all of the time.</li>
+ <li><code>null</code>, which can be used for HTML documents or when no namespace prefixes are used. Note that, if the <code>xpathExpression</code> contains a namespace prefix, this will result in a <code>DOMException</code> being thrown with the code <code>NAMESPACE_ERR</code>.</li>
+ <li>A custom user-defined function. See the <a href="#Implementing_a_User_Defined_Namespace_Resolver">Using a User Defined Namespace Resolver</a> section in the appendix for details.</li>
+ </ul>
+ </li>
+ <li><code>resultType</code>: Eine <a href="#XPathResult_Defined_Constants">Konstante</a>, die den gewünschten Rückgabetyp als Ergebnis der Auswertung angibt. Die am häufigsten übergebene Konstante ist <code>XPathResult.ANY_TYPE</code>, die eine Rückgabe der Ergebnisse in in einer Weise liefert, die den sebstverständlichen Erwartungen am ehesten entspricht. Im Anhang ist ein Abschnitt zu finden, der eine vollständige Liste der der <a href="#XPathResult_Defined_Constants">verfügbaren Konstanten</a> enthält. Sie werden weiter unten im Abschnitt  "<a href="#Specifying_the_Return_Type">Festlegung des Rückgabetyps</a>" erläutert.</li>
+ <li><code>result</code>: Wird ein vorhandenes <code>XPathResult</code>-Objekt angegeben, so wird es für die Ergebnisrückgabe wiederverwendet. Bei der Angabe von <code>null</code> wird ein neues <code>XPathResult</code>-Objekt erzeugt.</li>
+</ul>
+
+<h3 id="Return_Value" name="Return_Value">Rückgabewert</h3>
+
+<p>Returns <code>xpathResult</code>, which is an <code>XPathResult</code> object of the type <a href="#Specifying_the_Return_Type">specified</a> in the <code>resultType</code> parameter. The <code>XPathResult</code> Interface is defined {{ Source("dom/interfaces/xpath/nsIDOMXPathResult.idl", "here") }}.</p>
+
+<h3 id="Implementing_a_Default_Namespace_Resolver" name="Implementing_a_Default_Namespace_Resolver">Einen Standard-Namensraumauflöser (Default Namespace Resolver) implementieren</h3>
+
+<p>Wir erstellen einen Namensraumauflöser mit Hilfe der <code>createNSResolver</code>-Methode des <a href="/en-US/docs/Web/API/document" title="en/DOM/document">document</a>-Objekts.</p>
+
+<pre class="brush: js">var nsResolver = document.createNSResolver( contextNode.ownerDocument == null ? contextNode.documentElement : contextNode.ownerDocument.documentElement );
+</pre>
+
+<p><span class="comment">Or alternatively by using the &lt;code&gt;createNSResolver&lt;/code&gt; method of a &lt;code&gt;XPathEvaluator&lt;/code&gt; object. &lt;pre&gt; var xpEvaluator = new XPathEvaluator(); var nsResolver = xpEvaluator.createNSResolver( contextNode.ownerDocument == null ? contextNode.documentElement : contextNode.ownerDocument.documentElement ); &lt;/pre&gt;</span> And then pass <code>document.evaluate</code>, the <code>nsResolver</code> variable as the <code>namespaceResolver</code> parameter.</p>
+
+<p>Note: XPath defines QNames without a prefix to match only elements in the null namespace. There is no way in XPath to pick up the default namespace as applied to a regular element reference (e.g., <code>p[@id='_myid']</code> for <code><span class="nowiki">xmlns='http://www.w3.org/1999/xhtml</span>'</code>). To match default elements in a non-null namespace, you either have to refer to a particular element using a form such as <code>['namespace-uri()='<span class="nowiki">http://www.w3.org/1999/xhtml</span>' and name()='p' and @id='_myid']</code> (<a href="#Using_XPath_functions_to_reference_elements_with_a_default_namespace">this approach</a> works well for dynamic XPath's where the namespaces might not be known) or use prefixed name tests, and create a namespace resolver mapping the prefix to the namespace. Read more on <a href="#Implementing_a_User_Defined_Namespace_Resolver">how to create a user defined namespace resolver</a>, if you wish to take the latter approach.</p>
+
+<h3 id="Notes" name="Notes">Anmerkungen</h3>
+
+<p>Adapts any DOM node to resolve namespaces so that an <a href="/en-US/docs/XPath" title="en/XPath">XPath</a> expression can be easily evaluated relative to the context of the node where it appeared within the document. This adapter works like the DOM Level 3 method <code>lookupNamespaceURI</code> on nodes in resolving the <code>namespaceURI</code> from a given prefix using the current information available in the node's hierarchy at the time <code>lookupNamespaceURI</code> is called. Also correctly resolves the implicit <code>xml</code> prefix.</p>
+
+<h3 id="Specifying_the_Return_Type" name="Specifying_the_Return_Type">Festlegung des Rückgabetyps</h3>
+
+<p>The returned variable <code>xpathResult</code> from <code>document.evaluate</code> can either be composed of individual nodes (<a href="#Simple_Types">simple types</a>), or a collection of nodes (<a href="#Node-Set_Types">node-set types</a>).</p>
+
+<h4 id="Simple_Types" name="Simple_Types">Simple Types</h4>
+
+<p>When the desired result type in <code>resultType</code> is specified as either:</p>
+
+<ul>
+ <li><code>NUMBER_TYPE</code> - a double</li>
+ <li><code>STRING_TYPE</code> - a string</li>
+ <li><code>BOOLEAN_TYPE</code> - a boolean</li>
+</ul>
+
+<p>We obtain the returned value of the expression by accessing the following properties respectively of the <code>XPathResult</code> object.</p>
+
+<ul>
+ <li><code>numberValue</code></li>
+ <li><code>stringValue</code></li>
+ <li><code>booleanValue</code></li>
+</ul>
+
+<h5 id="Example" name="Example">Beispiel</h5>
+
+<p>The following uses the XPath expression <code><a href="/en-US/docs/XPath/Functions/count" title="en/XPath/Functions/count">count(//p)</a></code> to obtain the number of <code>&lt;p&gt;</code> elements in a HTML document:</p>
+
+<pre class="brush: js">var paragraphCount = document.evaluate( 'count(//p)', document, null, XPathResult.ANY_TYPE, null );
+
+alert( 'This document contains ' + paragraphCount.numberValue + ' paragraph elements' );
+</pre>
+
+<p>Although JavaScript allows us to convert the number to a string for display, the XPath interface will not automatically convert the numerical result if the <code>stringValue</code> property is requested, so the following code will <strong>not</strong> work:</p>
+
+<pre class="brush: js">var paragraphCount = document.evaluate('count(//p)', document, null, XPathResult.ANY_TYPE, null );
+
+alert( 'This document contains ' + paragraphCount.stringValue + ' paragraph elements' );
+</pre>
+
+<p>Instead it will return an exception with the code <code>NS_DOM_TYPE_ERROR</code>.</p>
+
+<h4 id="Node-Set_Types" name="Node-Set_Types">Node-Set-Typen</h4>
+
+<p>The <code>XPathResult</code> object allows node-sets to be returned in 3 principal different types:</p>
+
+<ul>
+ <li><a href="#Iterators">Iterators</a></li>
+ <li><a href="#Snapshots">Snapshots</a></li>
+ <li><a href="#First_Node">First Nodes</a></li>
+</ul>
+
+<h5 id="Iterators" name="Iterators">Iteratoren</h5>
+
+<p>When the specified result type in the <code>resultType</code> parameter is either:</p>
+
+<ul>
+ <li><code>UNORDERED_NODE_ITERATOR_TYPE</code></li>
+ <li><code>ORDERED_NODE_ITERATOR_TYPE</code></li>
+</ul>
+
+<p>The <code>XPathResult</code> object returned is a node-set of matched nodes which will behave as an iterator, allowing us to access the individual nodes contained by using the <code>iterateNext()</code> method of the <code>XPathResult</code>.</p>
+
+<p>Once we have iterated over all of the individual matched nodes, <code>iterateNext()</code> will return <code>null</code>.</p>
+
+<p>Note however, that if the document is mutated (the document tree is modified) between iterations that will invalidate the iteration and the <code>invalidIteratorState</code> property of <code>XPathResult</code> is set to <code>true</code>, and a <code>NS_ERROR_DOM_INVALID_STATE_ERR</code> exception is thrown.</p>
+
+<h6 id="Iterator_Example" name="Iterator_Example">Iterator Example</h6>
+
+<pre class="brush: js">var iterator = document.evaluate('//phoneNumber', documentNode, null, XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null );
+
+try {
+ var thisNode = iterator.iterateNext();
+
+ while (thisNode) {
+ alert( thisNode.textContent );
+ thisNode = iterator.iterateNext();
+ }
+}
+catch (e) {
+ dump( 'Error: Document tree modified during iteration ' + e );
+}
+</pre>
+
+<h5 id="Snapshots" name="Snapshots">Momentabbilder (Snapshots)</h5>
+
+<p>When the specified result type in the <code>resultType</code> parameter is either:</p>
+
+<ul>
+ <li><code>UNORDERED_NODE_SNAPSHOT_TYPE</code></li>
+ <li><code>ORDERED_NODE_SNAPSHOT_TYPE</code></li>
+</ul>
+
+<p>The <code>XPathResult</code> object returned is a static node-set of matched nodes, which allows us to access each node through the <code>snapshotItem(itemNumber)</code> method of the <code>XPathResult</code> object, where <code>itemNumber</code> is the index of the node to be retrieved. The total number of nodes contained can be accessed through the <code>snapshotLength</code> property.</p>
+
+<p>Snapshots do not change with document mutations, so unlike the iterators the snapshot does not become invalid, but it may not correspond to the current document, for example the nodes may have been moved, it might contain nodes that no longer exist, or new nodes could have been added.</p>
+
+<h6 id="Snapshot_Example" name="Snapshot_Example">Snapshot Example</h6>
+
+<pre class="brush: js">var nodesSnapshot = document.evaluate('//phoneNumber', documentNode, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null );
+
+for ( var i=0 ; i &lt; nodesSnapshot.snapshotLength; i++ )
+{
+ dump( nodesSnapshot.snapshotItem(i).textContent );
+}
+</pre>
+
+<h5 id="First_Node" name="First_Node">Erster Knoten</h5>
+
+<p>When the specified result type in the <code>resultType</code> parameter is either:</p>
+
+<ul>
+ <li><code>ANY_UNORDERED_NODE_TYPE</code></li>
+ <li><code>FIRST_ORDERED_NODE_TYPE</code></li>
+</ul>
+
+<p>The <code>XPathResult</code> object returned is only the first found node that matched the XPath expression. This can be accessed through the <code>singleNodeValue</code> property of the <code>XPathResult</code> object. This will be <code>null</code> if the node set is empty.</p>
+
+<p>Note that, for the unordered subtype the single node returned might not be the first in document order, but for the ordered subtype you are guaranteed to get the first matched node in the document order.</p>
+
+<h6 id="First_Node_Example" name="First_Node_Example">First Node Example</h6>
+
+<pre class="brush: js">var firstPhoneNumber = document.evaluate('//phoneNumber', documentNode, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null );
+
+dump( 'The first phone number found is ' + firstPhoneNumber.singleNodeValue.textContent );
+</pre>
+
+<h4 id="The_ANY_TYPE_Constant" name="The_ANY_TYPE_Constant">Die Konstante ANY_TYPE</h4>
+
+<p>When the result type in the <code>resultType</code> parameter is specified as <code>ANY_TYPE</code>, the <code>XPathResult</code> object returned, will be whatever type that naturally results from the evaluation of the expression.</p>
+
+<p>It could be any of the simple types (<code>NUMBER_TYPE, STRING_TYPE, BOOLEAN_TYPE</code>), <strong>but</strong>, if the returned result type is a node-set then it will <strong>only</strong> be an <code>UNORDERED_NODE_ITERATOR_TYPE</code>.</p>
+
+<p>To determine that type after evaluation, we use the <code>resultType</code> property of the <code>XPathResult</code> object. The <a href="#XPathResult_Defined_Constants">constant</a> values of this property are defined in the appendix. <span class="comment">None Yet =====Any_Type Example===== &lt;pre&gt; &lt;/pre&gt;</span></p>
+
+<h2 id="Examples" name="Examples">Beispiele</h2>
+
+<h3 id="Within_an_HTML_Document" name="Within_an_HTML_Document">Innerhalb eines HTML-Dokuments</h3>
+
+<p>The following code is intended to be placed in any JavaScript fragment within or linked to the HTML document against which the XPath expression is to be evaluated.</p>
+
+<p>To extract all the <code>&lt;h2&gt;</code> heading elements in an HTML document using XPath, the <code>xpathExpression</code> is simply '<code>//h2</code>'. Where, <code>//</code> is the Recursive Descent Operator that matches elements with the nodeName <code>h2</code> anywhere in the document tree. The full code for this is: <span class="comment">link to introductory xpath doc</span></p>
+
+<pre class="brush: js">var headings = document.evaluate('//h2', document, null, XPathResult.ANY_TYPE, null );
+</pre>
+
+<p>Notice that, since HTML does not have namespaces, we have passed <code>null</code> for the <code>namespaceResolver</code> parameter.</p>
+
+<p>Since we wish to search over the entire document for the headings, we have used the <a href="/en-US/docs/Web/API/document" title="en/DOM/document">document</a> object itself as the <code>contextNode</code>.</p>
+
+<p>The result of this expression is an <code>XPathResult</code> object. If we wish to know the type of result returned, we may evaluate the <code>resultType</code> property of the returned object. In this case, that will evaluate to <code>4</code>, an <code>UNORDERED_NODE_ITERATOR_TYPE</code>. This is the default return type when the result of the XPath expression is a node set. It provides access to a single node at a time and may not return nodes in a particular order. To access the returned nodes, we use the <code>iterateNext()</code> method of the returned object:</p>
+
+<pre class="brush: js">var thisHeading = headings.iterateNext();
+
+var alertText = 'Level 2 headings in this document are:\n'
+
+while (thisHeading) {
+ alertText += thisHeading.textContent + '\n';
+ thisHeading = headings.iterateNext();
+}
+</pre>
+
+<p>Once we iterate to a node, we have access to all the standard DOM interfaces on that node. After iterating through all the <code>h2</code> elements returned from our expression, any further calls to <code>iterateNext()</code> will return <code>null</code>.</p>
+
+<h3 id="Evaluating_against_an_XML_document_within_an_Extension" name="Evaluating_against_an_XML_document_within_an_Extension">Auswertung an einem XML-Dokument innerhalb einer Erweiterung</h3>
+
+<p>The following uses an XML document located at <span class="nowiki">chrome://yourextension/content/peopleDB.xml</span> as an example.</p>
+
+<pre class="brush: xml">&lt;?xml version="1.0"?&gt;
+&lt;people xmlns:xul = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" &gt;
+ &lt;person&gt;
+ &lt;name first="george" last="bush" /&gt;
+ &lt;address street="1600 pennsylvania avenue" city="washington" country="usa"/&gt;
+ &lt;phoneNumber&gt;202-456-1111&lt;/phoneNumber&gt;
+ &lt;/person&gt;
+ &lt;person&gt;
+ &lt;name first="tony" last="blair" /&gt;
+ &lt;address street="10 downing street" city="london" country="uk"/&gt;
+ &lt;phoneNumber&gt;020 7925 0918&lt;/phoneNumber&gt;
+ &lt;/person&gt;
+&lt;/people&gt;
+</pre>
+
+<p>To make the contents of the XML document available within the extension, we create an <code><a href="/en-US/docs/Web/API/XMLHttpRequest" title="en/XMLHttpRequest">XMLHttpRequest</a></code> object to load the document synchronously, the variable <code>xmlDoc</code> will contain the document as an <code><a href="/en-US/docs/Web/API/XMLDocument" title="en/XMLDocument">XMLDocument</a></code> object against which we can use the <code>evaluate</code> method</p>
+
+<p>JavaScript used in the extensions xul/js documents.</p>
+
+<pre class="brush: js">var req = new XMLHttpRequest();
+
+req.open("GET", "chrome://yourextension/content/peopleDB.xml", false);
+req.send(null);
+
+var xmlDoc = req.responseXML;
+
+var nsResolver = xmlDoc.createNSResolver( xmlDoc.ownerDocument == null ? xmlDoc.documentElement : xmlDoc.ownerDocument.documentElement);
+
+var personIterator = xmlDoc.evaluate('//person', xmlDoc, nsResolver, XPathResult.ANY_TYPE, null );
+</pre>
+
+<h3 id="Anmerkung">Anmerkung</h3>
+
+<p>When the XPathResult object is not defined, the constants can be retreived in privileged code using <code>Components.interfaces.nsIDOMXPathResult.ANY_TYPE</code> (<code>CI.nsIDOMXPathResult</code>). Similarly, an XPathEvaluator can be created using:</p>
+
+<pre class="brush: js">Components.classes["@mozilla.org/dom/xpath-evaluator;1"].createInstance(Components.interfaces.nsIDOMXPathEvaluator)</pre>
+
+<h2 id="Appendix" name="Appendix">Anhang</h2>
+
+<h4 id="Implementing_a_User_Defined_Namespace_Resolver" name="Implementing_a_User_Defined_Namespace_Resolver">Einen benutzerdefinierten Namensauflöser implementieren</h4>
+
+<p>This is an example for illustration only. This function will need to take namespace prefixes from the <code>xpathExpression</code> and return the URI that corresponds to that prefix. For example, the expression:</p>
+
+<pre>'//xhtml:td/mathml:math'
+</pre>
+
+<p>will select all <a href="/en-US/docs/Web/API/MathML" title="en/MathML">MathML</a> expressions that are the children of (X)HTML table data cell elements.</p>
+
+<p>In order to associate the '<code>mathml:</code>' prefix with the namespace URI '<code><span class="nowiki">http://www.w3.org/1998/Math/MathML</span></code>' and '<code>xhtml:</code>' with the URI '<code><span class="nowiki">http://www.w3.org/1999/xhtml</span></code>' we provide a function:</p>
+
+<pre class="brush: js">function nsResolver(prefix) {
+ var ns = {
+ 'xhtml' : 'http://www.w3.org/1999/xhtml',
+ 'mathml': 'http://www.w3.org/1998/Math/MathML'
+ };
+ return ns[prefix] || null;
+}
+</pre>
+
+<p>Our call to <code>document.evaluate</code> would then looks like:</p>
+
+<pre class="brush: js">document.evaluate( '//xhtml:td/mathml:math', document, nsResolver, XPathResult.ANY_TYPE, null );
+</pre>
+
+<h4 id="Implementing_a_default_namespace_for_XML_documents" name="Implementing_a_default_namespace_for_XML_documents">Einen Standard-Namensrauf für XML-Dokumente implementieren</h4>
+
+<p>As noted in the <a href="#Implementing_a_Default_Namespace_Resolver">Implementing a Default Namespace Resolver</a> previously, the default resolver does not handle the default namespace for XML documents. For example with this document:</p>
+
+<pre class="brush: xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
+&lt;feed xmlns="http://www.w3.org/2005/Atom"&gt;
+ &lt;entry /&gt;
+ &lt;entry /&gt;
+ &lt;entry /&gt;
+&lt;/feed&gt;
+</pre>
+
+<p><code>doc.evaluate('//entry', doc, nsResolver, XPathResult.ANY_TYPE, null)</code> will return an empty set, where <code>nsResolver</code> is the resolver returned by <code>createNSResolver</code>. Passing a <code>null</code> resolver doesn't work any better, either.</p>
+
+<p>One possible workaround is to create a custom resolver that returns the correct default namespace (the Atom namespace in this case). Note that you still have to use some namespace prefix in your XPath expression, so that the resolver function will be able to change it to your required namespace. E.g.:</p>
+
+<pre class="brush: js">function resolver() {
+ return 'http://www.w3.org/2005/Atom';
+}
+doc.evaluate('//myns:entry', doc, resolver, XPathResult.ANY_TYPE, null)
+</pre>
+
+<p>Note that a more complex resolver will be required if the document uses multiple namespaces.</p>
+
+<p>An approach which might work better (and allow namespaces not to be known ahead of time) is described in the next section.</p>
+
+<h4 id="Using_XPath_functions_to_reference_elements_with_a_default_namespace" name="Using_XPath_functions_to_reference_elements_with_a_default_namespace">Using XPath functions to reference elements with a default namespace</h4>
+
+<p>Another approach to match default elements in a non-null namespace (and one which works well for dynamic XPath expressions where the namespaces might not be known), involves referring to a particular element using a form such as <code>[namespace-uri()='<span class="nowiki">http://www.w3.org/1999/xhtml</span>' and name()='p' and @id='_myid']</code>. This circumvents the problem of an XPath query not being able to detect the default namespace on a regularly labeled element.</p>
+
+<h4 id="Getting_specifically_namespaced_elements_and_attributes_regardless_of_prefix" name="Getting_specifically_namespaced_elements_and_attributes_regardless_of_prefix">Getting specifically namespaced elements and attributes regardless of prefix</h4>
+
+<p>If one wishes to provide flexibility in namespaces (as they are intended) by not necessarily requiring a particular prefix to be used when finding a namespaced element or attribute, one must use special techniques.</p>
+
+<p>While one can adapt the approach in the above section to test for namespaced elements regardless of the prefix chosen (using <code><a href="/en-US/docs/XPath/Functions/local-name" title="en/XPath/Functions/local-name">local-name()</a></code> in combination with <code><a href="/en-US/docs/XPath/Functions/namespace-uri" title="en/XPath/Functions/namespace-uri">namespace-uri()</a></code> instead of <code><a href="/en-US/docs/XPath/Functions/name" title="en/XPath/Functions/name">name()</a></code>), a more challenging situation occurs, however, if one wishes to grab an element with a particular namespaced attribute in a predicate (given the absence of implementation-independent variables in XPath 1.0).</p>
+
+<p>For example, one might try (incorrectly) to grab an element with a namespaced attribute as follows: <code>var xpathlink = someElements[local-name(@*)="href" and namespace-uri(@*)='<span class="nowiki">http://www.w3.org/1999/xlink</span>'];</code></p>
+
+<p>This could inadvertently grab some elements if one of its attributes existed that had a local name of "<code>href</code>", but it was a different attribute which had the targeted (XLink) namespace (instead of <code><a href="/en/XPath/Axes/attribute" title="en/XPath/Axes/attribute">@href</a></code>).</p>
+
+<p>In order to accurately grab elements with the XLink <code>@href</code> attribute (without also being confined to predefined prefixes in a namespace resolver), one could obtain them as follows:</p>
+
+<pre class="brush: js">var xpathEls = 'someElements[@*[local-name() = "href" and namespace-uri() = "http://www.w3.org/1999/xlink"]]'; // Grabs elements with any single attribute that has both the local name 'href' and the XLink namespace
+var thislevel = xml.evaluate(xpathEls, xml, null, XPathResult.ANY_TYPE, null);
+var thisitemEl = thislevel.iterateNext();
+</pre>
+
+<h4 id="XPathResult_Defined_Constants" name="XPathResult_Defined_Constants">In XPathResult definierte Konstanten</h4>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <td class="header">Result Type Defined Constant</td>
+ <td class="header">Value</td>
+ <td class="header">Description</td>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>ANY_TYPE</td>
+ <td>0</td>
+ <td>A result set containing whatever type naturally results from evaluation of the expression. Note that if the result is a node-set then UNORDERED_NODE_ITERATOR_TYPE is always the resulting type.</td>
+ </tr>
+ <tr>
+ <td>NUMBER_TYPE</td>
+ <td>1</td>
+ <td>A result containing a single number. This is useful for example, in an XPath expression using the <code>count()</code> function.</td>
+ </tr>
+ <tr>
+ <td>STRING_TYPE</td>
+ <td>2</td>
+ <td>A result containing a single string.</td>
+ </tr>
+ <tr>
+ <td>BOOLEAN_TYPE</td>
+ <td>3</td>
+ <td>A result containing a single boolean value. This is useful for example, in an XPath expression using the <code>not()</code> function.</td>
+ </tr>
+ <tr>
+ <td>UNORDERED_NODE_ITERATOR_TYPE</td>
+ <td>4</td>
+ <td>A result node-set containing all the nodes matching the expression. The nodes may not necessarily be in the same order that they appear in the document.</td>
+ </tr>
+ <tr>
+ <td>ORDERED_NODE_ITERATOR_TYPE</td>
+ <td>5</td>
+ <td>A result node-set containing all the nodes matching the expression. The nodes in the result set are in the same order that they appear in the document.</td>
+ </tr>
+ <tr>
+ <td>UNORDERED_NODE_SNAPSHOT_TYPE</td>
+ <td>6</td>
+ <td>A result node-set containing snapshots of all the nodes matching the expression. The nodes may not necessarily be in the same order that they appear in the document.</td>
+ </tr>
+ <tr>
+ <td>ORDERED_NODE_SNAPSHOT_TYPE</td>
+ <td>7</td>
+ <td>A result node-set containing snapshots of all the nodes matching the expression. The nodes in the result set are in the same order that they appear in the document.</td>
+ </tr>
+ <tr>
+ <td>ANY_UNORDERED_NODE_TYPE</td>
+ <td>8</td>
+ <td>A result node-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>FIRST_ORDERED_NODE_TYPE</td>
+ <td>9</td>
+ <td>A result node-set containing the first node in the document that matches the expression.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="See_also" name="See_also">Siehe auch</h2>
+
+<ul>
+ <li><a href="/en-US/docs/Web/XPath">XPath</a></li>
+ <li><a href="http://www.xml.com/pub/a/2000/08/holman/index.html?page=2#xpath-info">XML Path Language </a>from <em><a href="http://www.xml.com/pub/a/2000/08/holman/">What is XSLT?</a> </em>by G. Ken Holman</li>
+</ul>
+
+<div class="originaldocinfo">
+<h2 id="Original_Document_Information" name="Original_Document_Information">Original Document Information</h2>
+
+<ul>
+ <li>Based Upon Original Document <a class="external" href="http://www-xray.ast.cam.ac.uk/~jgraham/mozilla/xpath-tutorial.html">Mozilla XPath Tutorial</a></li>
+ <li>Original Source Author: James Graham.</li>
+ <li>Other Contributors: James Thompson.</li>
+ <li>Last Updated Date: 2006-3-25.</li>
+</ul>
+</div>