Last active
October 23, 2022 03:01
-
-
Save lighth7015/89504b6db719231882390b9a922503ad to your computer and use it in GitHub Desktop.
Issue querying for namespaced child fragments.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$template =<<<EOF | |
<!DOCTYPE html> | |
<html xmlns:x="http://schema.hpprx.com/schemas"> | |
<head></head> | |
<body> | |
<div x:for-each="(foo, i) of bar"> | |
a | |
</div> | |
</body> | |
</html> | |
EOF; | |
class Template { | |
private DOMDocument $doc; | |
public function __construct(string $buffer) { | |
$doc = $this->doc = new DOMDocument; | |
$doc->loadHTML($buffer); | |
} | |
private static function xpath(string $attribute): string { | |
$path = sprintf('//*[@x:%s]', $attribute); | |
var_dump($path); | |
return $path; | |
} | |
public function queryElements(string $attribute) { | |
$xpath = new DOMXPath($this->doc); | |
$xpath->registerNamespace('x', 'http://schema.hpprx.com'); | |
// var_dump($this->doc->saveHTML(null)); | |
return $xpath->query(static::xpath($attribute)); | |
} | |
} | |
$loader = new Template($template); | |
var_dump($loader->queryElements('for-each')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment