protected function parseContent(\DomDocument $xml, $chapter_title) { $element = $xml->documentElement; $node_list = $element->childNodes; $chapter_node = ''; $index = 0; // loop through child siblings for ($i = 0; $i < $node_list->length; $i++) { $chapter_node = $this->findTheNode($node_list->item($i), $chapter_title); if ('' != $chapter_node) { // assumes h1 is going to be first child of parent 'html' $index = $i; break; } } if ($chapter_node) { $chapter_title = strtolower(preg_replace('/\\s+/', '-', $chapter_node->nodeValue)); } // iterate through return $this->getChapter($node_list, $index, $chapter_title); }