Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Just seeing that Salathe actually answered the same, but taking your comment into account and to stress this a bit more:</p> <p>You do not need to specify any DTD. As long as you use the <code>DOMDocument::loadHTML</code> or <code>DOMDocument::loadHTMLFile</code> functions, the HTML <code>id</code> attribute is actually registered for the the xpath <code>id()</code> function. With the demo HTML given in <a href="http://jsbin.com/elatum/2/edit" rel="noreferrer">http://jsbin.com/elatum/2/edit</a>, you even get an error when you load the document:</p> <blockquote> <p>Warning: DOMDocument::loadHTMLFile(): ID priceInfo already defined in ...</p> </blockquote> <p>Which is already a sign that this is a true ID attribute because it moans about duplicates. A related sample code looks like:</p> <pre><code>$xpath = 'id("priceInfo")/div[@class="standardProdPricingGroup"]/span[1]'; $doc = new DOMDocument(); $doc-&gt;loadHTMLFile(__DIR__ . '/../data/file-11796340.html'); $xp = new DOMXPath($doc); $r = $xp-&gt;query($xpath); echo $xpath, "\n"; echo $r ? $r-&gt;length : 0, ' elements found', "\n"; if (!$r) return; foreach($r as $node) { echo " - ", $node-&gt;nodeValue, "\n"; } </code></pre> <p>The output is:</p> <pre><code>id("priceInfo")/div[@class="standardProdPricingGroup"]/span[1] 1 elements found - hello </code></pre> <p>In case you need more control, first run an xpath to mark all HTML <code>id</code> attributes as ID for xpath:</p> <pre><code>$r = $xp-&gt;query("//*[@id]"); if ($r) foreach($r as $node) { $node-&gt;setIdAttribute('id', true); } </code></pre> <p>You can then use the same xpath with the <code>id()</code> function, no need to change it.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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