Index: import/leap/lib.php =================================================================== --- import/leap/lib.php (revision 8) +++ import/leap/lib.php (working copy) @@ -124,6 +124,13 @@ ; libxml_before(false); require_once('file.php'); + + /* + + * following code commented out as it fails on   + * replacement is a little heavy on debugging + * but it should be more helpful with xml errors + if (!$this->xml = simplexml_load_string( preg_replace(xml_filter_regex(), '', file_get_contents($this->filename)), 'SimpleXMLElement', @@ -133,6 +140,37 @@ libxml_after(); throw new ImportException($this, "FATAL: XML file is not well formed! Please consult Mahara's error log for more information"); } + */ + + libxml_use_internal_errors(true); + $raw_contents = file_get_contents( $this->filename ); + + // choking on   so let's replace them! + $cooked_contents = preg_replace( '/ /', ' ', $raw_contents ); + $sxe = simplexml_load_string( + preg_replace(xml_filter_regex(), '', $cooked_contents ), + 'SimpleXMLElement', + $options + ); + if( $sxe === false ) { + $msg = []; + $msg[] = 'FATAL: XML not well formed'; + foreach(libxml_get_errors() as $error) { + $msg[] = $error->message; + } + + // uncomment for even more data + // $msg[] = 'INPUT'; + // $msg[] = $cooked_contents; + libxml_after(); + $msgString = implode( "\n", $msg ); + throw new ImportException( $this, $msgString ); + } + // don't actually need 'else' just easier to understand what's going on + else { + $this->xml = $sxe; + } + libxml_after(); $this->namespaces = array_flip($this->xml->getDocNamespaces());