问题
I exported a xml file in PHP using:
$xmldoc = new DOMDocument();
$xmldoc->formatOutput = true;
$xmldoc->encoding="Shift_JIS";
// create root nodes
$root = $xmldoc->createElement("TableData");
$xmldoc->appendChild( $root );
$xmldoc->save($filename);
Result:
<?xml version="1.0" encoding="Shift_JIS"?>
<TableData> </TableData>
Now, i want to add row <!DOCTYPE TableDef SYSTEM "TableData.dtd">
like:
<?xml version="1.0" encoding="Shift_JIS"?>
<!DOCTYPE TableDef SYSTEM "TableData.dtd">
<TableData> </TableData>
How to add DOCTYPE
in an exported xml? Thanks.
回答1:
See PHP DOM: change doctype of existing DOMDocument
When creating a DOMDocument with DOMImplementation::createDocument(), you can specify a doctype as the third argument in the constructor. This doctype then gets "tied" to the document and you can retrieve it later with $document->doctype.
来源:https://stackoverflow.com/questions/13339976/how-to-add-doctype-in-export-xml