我正在使用 PHP 创建一个 XML 文件。XML 的结构是正确的,但是当我从浏览器中选择“查看源代码”时,所有代码都输出在一行中。
我正在尝试调试一个错误,它指向我的代码行(第 2 行),但这并不像它在多行代码上那样有用。我正在从数据库中提取数据,虽然代码在有限的测试规模上工作,但在使用所有数据时它给了我一个错误。
错误:
DOMDocument::schemaValidate() Generated Errors! Fatal Error 68: xmlParseEntityRef: no name in (/home2/path...)"
下面是我用来创建 XML 的 PHP 的开头...
<?php
/* create a dom document with encoding utf8 */
$domtree = new DOMDocument('1.0', 'UTF-8');
/* create the root element of the xml tree */
$xmlRoot = $domtree->createElement('BatchDataSet');
/* append it to the document created */
$xmlRoot = $domtree->appendChild($xmlRoot);
$xmlRoot->setAttribute("SchemaVersion","1.0");
$xmlRoot->setAttribute("Quarter","2");
$xmlRoot->setAttribute("Year","2012");
// INSURER INFO: A INSURANCE
$insurer = $domtree->createElement("Insurer");
$insurer = $xmlRoot->appendChild($insurer);
$insurer->appendChild($domtree->createElement('NAICNumber','12345'));
$insurer->appendChild($domtree->createElement('Name','Example'));
$contact = $domtree->createElement("Contact");
$contact = $insurer->appendChild($contact);
$contact->appendChild($domtree->createElement('FirstName', 'Kim'));
$contact->appendChild($domtree->createElement('LastName','Smith'));
$contact->appendChild($domtree->createElement('EmailAddress','Kim@ins.co'));
......................