Browse Source

Added Node::getNodePath

master 1.0.1
Dustin Wilson 2 years ago
parent
commit
228a11cb44
  1. 7
      README.md
  2. 4
      lib/Node.php
  3. 7
      tests/cases/TestNode.php

7
README.md

@ -229,9 +229,16 @@ partial abstract class Node implements \Stringable {
public const WALK_REJECT = 0x02;
public const WALK_SKIP_CHILDREN = 0x04;
public const WALK_STOP = 0x08;
public function getNodePath(): ?string;
}
```
#### MensBeam\HTML\DOM\Node::getNodePath ####
Carryover from PHP's DOM. It's a useful method that returns an XPath location path for the node. Returns a string if successful or null on failure.
### MensBeam\HTML\DOM\ParentNode ###
```php

4
lib/Node.php

@ -436,6 +436,10 @@ abstract class Node implements \Stringable {
return $this->containsInner($this->innerNode, $this->getInnerNode($other));
}
public function getNodePath(): ?string {
return $this->innerNode->getNodePath();
}
public function getRootNode(): ?Node {
# The getRootNode(options) method steps are to return this’s shadow-including
# root if options["composed"] is true; otherwise this’s root.

7
tests/cases/TestNode.php

@ -265,6 +265,13 @@ class TestNode extends \PHPUnit\Framework\TestCase {
}
public function testMethod_getNodePath(): void {
$d = new Document('<!DOCTYPE html><html><body><div><span><div></div><div><p><span><div></div><div></div><span></span><p id="ook">ook</p></span></p></div></span></div></body></html>');
$ook = $d->getElementById('ook');
$this->assertSame('/html/body/div/span/div[2]/p[2]', $ook->getNodePath());
}
/**
* @covers \MensBeam\HTML\DOM\Node::insertBefore
*

Loading…
Cancel
Save