protected function findTheNode(\DOMNode $node, $chapter_name)
{
if (XML_ELEMENT_NODE !== $node->nodeType) {
return '';
}
$currentTag = $node->tagName;
$currentValue = trim($node->nodeValue);
if ($chapter_name == $currentValue && $this->tag == $currentTag) {
return $node;
}
// test
if ($node->hasChildNodes()) {
$nodeList = $node->childNodes;
for ($i = 0; $i < $nodeList->length; $i++) {
if ($nodeList->item($i)->nodeType !== XML_ELEMENT_NODE) {
continue;
}
if ($chapter_name != $nodeList->item($i)->nodeValue && $this->tag != $nodeList->item($i)->tagName) {
// recursive
return $this->findTheNode($nodeList->item($i), $chapter_name);
}
}
}
return '';
}