1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
<?php
namespace phpdotnet\phd;
class Reader extends \XMLReader
{
const XMLNS_XML = "http://www.w3.org/XML/1998/namespace";
const XMLNS_XLINK = "http://www.w3.org/1999/xlink";
const XMLNS_PHD = "http://www.php.net/ns/phd";
const XMLNS_DOCBOOK = "http://docbook.org/ns/docbook";
protected OutputHandler $outputHandler;
public function __construct(OutputHandler $outputHandler) {
$this->outputHandler = $outputHandler;
}
/* Get the content of a named node, or the current node. */
public function readContent(?string $node = null): string {
$retval = "";
if($this->isEmptyElement) {
return $retval;
}
if (!$node) {
// We need libxml2.6.20 to be able to read the textual content of the node without skipping over the markup too
if (\LIBXML_VERSION >= 20620) {
return self::readString();
}
$this->outputHandler->v("You are using libxml2 v%d, but v20620 or newer is preferred", \LIBXML_VERSION, VERBOSE_OLD_LIBXML);
$node = $this->name;
}
while (self::readNode($node)) {
$retval .= $this->value;
}
return $retval;
}
private function readNode(string $nodeName): bool {
return self::read() && !($this->nodeType === self::END_ELEMENT && $this->name === $nodeName);
}
}
|