protected function findTheNode( \DOMNode $node, $chapter_name ) {

		if ( XML_ELEMENT_NODE !== $node->nodeType ) {
			return '';
		}

		$current_tag = $node->tagName;
		$current_value = trim( $node->nodeValue );

		if ( $chapter_name === $current_value && $this->tag === $current_tag ) {
			return $node;
		}
		// test
		if ( $node->hasChildNodes() ) {
			$node_list = $node->childNodes;

			for ( $i = 0; $i < $node_list->length; $i++ ) {

				if ( $node_list->item( $i )->nodeType !== XML_ELEMENT_NODE ) {
					continue;
				}

				if ( $chapter_name !== $node_list->item( $i )->nodeValue && $this->tag !== $node_list->item( $i )->tagName ) {
					// recursive
					return $this->findTheNode( $node_list->item( $i ), $chapter_name );
				}
			}
		}

		return '';
	}
protected function findTheNode( \DOMNode $node, $chapter_name ) {

		if ( XML_ELEMENT_NODE !== $node->nodeType ) {
			return '';
		}

		$current_tag = $node->tagName;
		$current_value = trim( $node->nodeValue );

		if ( $chapter_name === $current_value && $this->tag === $current_tag ) {
			return $node;
		}
		// test
		if ( $node->hasChildNodes() ) {
			$node_list = $node->childNodes;

			for ( $i = 0; $i < $node_list->length; $i++ ) {

				if ( $node_list->item( $i )->nodeType !== XML_ELEMENT_NODE ) {
					continue;
				}

				if ( $chapter_name !== $node_list->item( $i )->nodeValue && $this->tag !== $node_list->item( $i )->tagName ) {
					// recursive
					return $this->findTheNode( $node_list->item( $i ), $chapter_name );
				}
			}
		}

		return '';
	}
protected function findTheNode ( \ DOMNode $ node , $ chapter_name ) { if ( XML_ELEMENT_NODE !== $ node -> nodeType ) { return '' ; } $ current_tag = $ node -> tagName ; $ current_value = trim ( $ node -> nodeValue ) ; if ( $ chapter_name === $ current_value && $ this -> tag === $ current_tag ) { return $ node ; } // test if ( $ node -> hasChildNodes ( ) ) { $ node_list = $ node -> childNodes ; for ( $ i = 0 ; $ i < $ node_list -> length ; $ i ++ ) { if ( $ node_list -> item ( $ i ) -> nodeType !== XML_ELEMENT_NODE ) { continue ; } if ( $ chapter_name !== $ node_list -> item ( $ i ) -> nodeValue && $ this -> tag !== $ node_list -> item ( $ i ) -> tagName ) { // recursive return $ this -> findTheNode ( $ node_list -> item ( $ i ) , $ chapter_name ) ; } } } return '' ; }
Recursive iterator to locate and return a specific node, targeting child nodes

@param \DOMNode $node
@param string $chapter_name

@return \DOMNode|mixed
Recursive iterator to locate and return a specific node targeting child nodes