如何在导出xml中添加DOCTYPE? [英] How to add DOCTYPE in export xml?
本文介绍了如何在导出xml中添加DOCTYPE?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用以下命令在PHP中导出了一个xml文件:
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);
结果:
<?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
?谢谢。
How to add DOCTYPE
in an exported xml? Thanks.
推荐答案
请参见 PHP DOM:更改现有DOMDocument的文档类型
使用< a href = http://www.php.net/manual/zh/domimplementation.createdocument.php rel = nofollow noreferrer> DOMImplementation :: createDocument(),
您可以指定一个doctype作为构造函数中的第三个参数。
然后将此文档类型束缚到文档中,稍后您可以使用$ document-> doctype来检索它
。
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.
这篇关于如何在导出xml中添加DOCTYPE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文