How to add DOCTYPE in export xml?

喜你入骨 提交于 2020-01-21 11:26:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!