protected function loadIncludes($xmlPath, $xmlString)
    {
        $m = null;
        if (preg_match_all("/\<include\s*href\=\"([^\"]+)\".*?\/\>/si", $xmlString, $m, PREG_SET_ORDER) !== false) {
            foreach ($m as $match) {
                $includeFile = rtrim($xmlPath, '/').'/'.$match[1];
                if (file_exists($includeFile)) {
                    $includeString = file_get_contents($includeFile);
                    $includeString = $this->loadIncludes(dirname($includeFile), $includeString);
                    $xmlString = str_replace($match[0], $includeString, $xmlString);
                } else {
                    throw new Exception("XML include file not found: {$includeFile}");
                }
            }
        }

        return $xmlString;
    }
protected function loadIncludes($xmlPath, $xmlString)
    {
        $m = null;
        if (preg_match_all("/\<include\s*href\=\"([^\"]+)\".*?\/\>/si", $xmlString, $m, PREG_SET_ORDER) !== false) {
            foreach ($m as $match) {
                $includeFile = rtrim($xmlPath, '/').'/'.$match[1];
                if (file_exists($includeFile)) {
                    $includeString = file_get_contents($includeFile);
                    $includeString = $this->loadIncludes(dirname($includeFile), $includeString);
                    $xmlString = str_replace($match[0], $includeString, $xmlString);
                } else {
                    throw new Exception("XML include file not found: {$includeFile}");
                }
            }
        }

        return $xmlString;
    }
protected function loadIncludes ( $ xmlPath , $ xmlString ) { $ m = null ; if ( preg_match_all ( "/\<include\s*href\=\"([^\"]+)\".*?\/\>/si" , $ xmlString , $ m , PREG_SET_ORDER ) !== false ) { foreach ( $ m as $ match ) { $ includeFile = rtrim ( $ xmlPath , '/' ) . '/' . $ match [ 1 ] ; if ( file_exists ( $ includeFile ) ) { $ includeString = file_get_contents ( $ includeFile ) ; $ includeString = $ this -> loadIncludes ( dirname ( $ includeFile ) , $ includeString ) ; $ xmlString = str_replace ( $ match [ 0 ] , $ includeString , $ xmlString ) ; } else { throw new Exception ( "XML include file not found: {$includeFile}" ) ; } } } return $ xmlString ; }
Loads all the includes into the xml string.

@param string $xmlPath   The absolute path to the directory where the include files are located
@param string $xmlString The full XML string (usually file contents from an xml doc)

@return string the full xml string with any includes replaced by the included content
Loads all the includes into the xml string .