protected function getChapter( \DOMNodeList $dom_list, $index, $chapter_title ) {

		if ( empty( $chapter_title ) ) {
			$chapter_title = 'unknown';
		}
		$chapter = new \DOMDocument( '1.0', 'UTF-8' );

		// create a new node element
		$root = $chapter->createElement( 'div' );
		$root->setAttribute( 'class', $chapter_title );

		$chapter->appendChild( $root );

		// Start at the beginning if no h1 tags are found.
		// In other words...bring in the whole document.
		( '__UNKNOWN__' === $chapter_title ) ? $i = 0 : $i = $index;

		do {
			$node = $chapter->importNode( $dom_list->item( $i ), true );
			$chapter->documentElement->appendChild( $node );
			$i++;

			// TODO
			// This is problematic
			// DOMNodeList can be made up of DOMElement(s)
			// *and* DOMText(s) which do not have the property ->tagName

		} while ( @$dom_list->item( $i )->tagName != $this->tag && $i < $dom_list->length ); // @codingStandardsIgnoreLine

		// h1 tag will not be needed in the body of the html
		$h1 = $chapter->getElementsByTagName( $this->tag )->item( 0 );

		// removeChild is quick to throw a fatal error
		if ( $h1 && $this->tag === $h1->nodeName && 'div' === $h1->parentNode->nodeName ) {
			$chapter->documentElement->removeChild( $h1 );
		}

		$result = $chapter->saveHTML( $chapter->documentElement );

		// appendChild brings over the namespace which is superfluous on every html element
		// the string below is from the xslt file
		// @see includes/modules/import/odf/xsl/odt2html.xsl
		$result = preg_replace( '/xmlns="http:\/\/www.w3.org\/1999\/xhtml"/', '', $result );

		return $result;
	}
protected function getChapter( \DOMNodeList $dom_list, $index, $chapter_title ) {

		if ( empty( $chapter_title ) ) {
			$chapter_title = 'unknown';
		}
		$chapter = new \DOMDocument( '1.0', 'UTF-8' );

		// create a new node element
		$root = $chapter->createElement( 'div' );
		$root->setAttribute( 'class', $chapter_title );

		$chapter->appendChild( $root );

		// Start at the beginning if no h1 tags are found.
		// In other words...bring in the whole document.
		( '__UNKNOWN__' === $chapter_title ) ? $i = 0 : $i = $index;

		do {
			$node = $chapter->importNode( $dom_list->item( $i ), true );
			$chapter->documentElement->appendChild( $node );
			$i++;

			// TODO
			// This is problematic
			// DOMNodeList can be made up of DOMElement(s)
			// *and* DOMText(s) which do not have the property ->tagName

		} while ( @$dom_list->item( $i )->tagName != $this->tag && $i < $dom_list->length ); // @codingStandardsIgnoreLine

		// h1 tag will not be needed in the body of the html
		$h1 = $chapter->getElementsByTagName( $this->tag )->item( 0 );

		// removeChild is quick to throw a fatal error
		if ( $h1 && $this->tag === $h1->nodeName && 'div' === $h1->parentNode->nodeName ) {
			$chapter->documentElement->removeChild( $h1 );
		}

		$result = $chapter->saveHTML( $chapter->documentElement );

		// appendChild brings over the namespace which is superfluous on every html element
		// the string below is from the xslt file
		// @see includes/modules/import/odf/xsl/odt2html.xsl
		$result = preg_replace( '/xmlns="http:\/\/www.w3.org\/1999\/xhtml"/', '', $result );

		return $result;
	}
protected function getChapter ( \ DOMNodeList $ dom_list , $ index , $ chapter_title ) { if ( empty ( $ chapter_title ) ) { $ chapter_title = 'unknown' ; } $ chapter = new \ DOMDocument ( '1.0' , 'UTF-8' ) ; // create a new node element $ root = $ chapter -> createElement ( 'div' ) ; $ root -> setAttribute ( 'class' , $ chapter_title ) ; $ chapter -> appendChild ( $ root ) ; // Start at the beginning if no h1 tags are found. // In other words...bring in the whole document. ( '__UNKNOWN__' === $ chapter_title ) ? $ i = 0 : $ i = $ index ; do { $ node = $ chapter -> importNode ( $ dom_list -> item ( $ i ) , true ) ; $ chapter -> documentElement -> appendChild ( $ node ) ; $ i ++ ; // TODO // This is problematic // DOMNodeList can be made up of DOMElement(s) // *and* DOMText(s) which do not have the property ->tagName } while ( @ $ dom_list -> item ( $ i ) -> tagName != $ this -> tag && $ i < $ dom_list -> length ) ; // @codingStandardsIgnoreLine // h1 tag will not be needed in the body of the html $ h1 = $ chapter -> getElementsByTagName ( $ this -> tag ) -> item ( 0 ) ; // removeChild is quick to throw a fatal error if ( $ h1 && $ this -> tag === $ h1 -> nodeName && 'div' === $ h1 -> parentNode -> nodeName ) { $ chapter -> documentElement -> removeChild ( $ h1 ) ; } $ result = $ chapter -> saveHTML ( $ chapter -> documentElement ) ; // appendChild brings over the namespace which is superfluous on every html element // the string below is from the xslt file // @see includes/modules/import/odf/xsl/odt2html.xsl $ result = preg_replace ( '/xmlns="http:\/\/www.w3.org\/1999\/xhtml"/' , '' , $ result ) ; return $ result ; }
Find where to start, iterate through a list, add elements to a
new DomDocument, return resulting xhtml

@param \DOMNodeList $dom_list
@param int $index
@param string $chapter_title

@return string XHTML
Find where to start iterate through a list add elements to a new DomDocument return resulting xhtml