我将从URL生成的XML保存到XML文件中。然后我尝试用PHP打开它并使用PHPExcel将其保存为Excel2007文件。但是我为XML数据文件中的每个标记得到以下内容,每一个标记都是:
警告:DOMDocument :: loadHTMLFile():标记(注意:此标记名称在此处对每个标记都会更改)结果无效 ./data.xml,第2行:C:\ wamp \ www \ project \ inc \ functions.inc.php on 第48行
这是在页面的最后,包含所有警告:
致命错误:找不到类'SimpleXML' 第58行的C:\ wamp \ www \ project \ inc \ functions.inc.php
这是代码:
$sxml->asXML('data.xml'); // save as xml to server
$dom = new DOMDocument("1.0", "utf-8");
$dom->recover = true;
$dom->strictErrorChecking = false;
$dom->loadHTMLFile('./data.xml'); // LINE 48
if (!$dom)
{
throw new Exception("Could not load the lax XML file");
}
// Now you can work with your XML file using the $dom object.
// If you'd like using SimpleXML, do the following steps.
$xml = new SimpleXML($dom->saveXML()); // LINE 58
unset($dom);
/** PHPExcel_IOFactory */
require_once dirname(__FILE__) . '/../Classes/PHPExcel/IOFactory.php';
$inputFileName = "./data.xml";
/** Identify the type of $inputFileName **/
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
/** Create a new Reader of the type that has been identified **/
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
/** Load $inputFileName to a PHPExcel Object **/
$objPHPExcel = $objReader->load($inputFileName);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save(str_replace('.php', '.xlsx', __FILE__));