Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You did not <a href="http://php.net/manual/en/domxpath.registernamespace.php" rel="noreferrer">register the XML namespace</a> before the query.</p> <pre><code>// register it $xpath-&gt;registerNamespace('kml', "http://earth.google.com/kml/2.1"); // and use it, too ! $query = $xpath-&gt;query("//kml:Placemark[kml:type='Public/Daily Fee']"); </code></pre> <p><em>(the <code>ancestor::kml:Placemark</code> in your expression made no sense, I left it out.)</em></p> <p>The namespace prefix in the XPath query must be used even if the namespace in question is the <em>default namespace</em> of the XML document (like in your case).</p> <p>The element <code>&lt;kml xmlns="http://earth.google.com/kml/2.1"&gt;</code> is equivalent to <code>&lt;kml:kml xmlns:kml="http://earth.google.com/kml/2.1"</code>>. </p> <p>However, an XPath query of <code>/kml</code> is not equivalent to <code>/kml:kml</code>. The latter would match both elements (when the <code>kml</code> namespace is registered beforehand), the former would match none of them, no matter what you do.</p> <p>Also note that you do not <em>need</em> to use the same namespace prefix that is used in the XML document. </p> <p>Assume the XML document is this:</p> <pre><code>&lt;kml:kml xmlns:kml="http://earth.google.com/kml/2.1"&gt; &lt;kml:Document /&gt; &lt;/kml:kml&gt; </code></pre> <p>Then you could still do this:</p> <pre><code>$xpath-&gt;registerNamespace('foo', "http://earth.google.com/kml/2.1"); $query = $xpath-&gt;query("/foo:kml/foo:Document"); </code></pre> <p>and get back a correct result. Namespace prefixes are just a shorthand.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload