如何在export xml中添加DOCTYPE?

时间:2012-11-12 07:51:26

标签: php xml domdocument doctype

我使用以下方法在PHP中导出了一个xml文件:

$xmldoc = new DOMDocument();        
$xmldoc->formatOutput = true;
$xmldoc->encoding="Shift_JIS";

// create root nodes
$root = $xmldoc->createElement("TableData");
$xmldoc->appendChild( $root );
$xmldoc->save($filename);

结果:

<?xml version="1.0" encoding="Shift_JIS"?>
<TableData> </TableData>

现在,我想添加行<!DOCTYPE TableDef SYSTEM "TableData.dtd">,如:

    <?xml version="1.0" encoding="Shift_JIS"?>
    <!DOCTYPE TableDef SYSTEM "TableData.dtd">
   <TableData> </TableData>

如何在导出的xml中添加DOCTYPE?感谢。

1 个答案:

答案 0 :(得分:3)

请参阅PHP DOM: change doctype of existing DOMDocument

  

使用DOMImplementation::createDocument()创建DOMDocument时,   您可以将doctype指定为构造函数中的第三个参数。   然后,此doctype与文档“绑定”,您可以检索它   稍后使用$ document-&gt; doctype。