首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

DOMImplementation::createDocumentType

(PHP 5, PHP 7)

DOMImplementation :: createDocumentType - 创建一个空的DOMDocumentType对象

描述

代码语言:javascript
复制
public DOMDocumentType DOMImplementation::createDocumentType ([ string $qualifiedName = NULL [, string $publicId = NULL [, string $systemId = NULL ]]] )

创建一个空的DOMDocumentType对象。实体声明和符号不可用。不会发生实体引用扩展和默认属性添加。

参数

qualifiedName

要创建的文档类型的限定名称。

publicId

外部子集公共标识符。

systemId

外部子集系统标识符。

返回值

ownerDocument设置为的新DOMDocumentType节点NULL

错误/异常

DOM_NAMESPACE_ERR

如果由命名空间发生错误,则引发qualifiedName

This method may be called statically, but will issue an E_STRICT error.

例子

示例#1使用附加的DTD创建文档

代码语言:javascript
复制
<?php

// Creates an instance of the DOMImplementation class
$imp = new DOMImplementation;

// Creates a DOMDocumentType instance
$dtd = $imp->createDocumentType('graph', '', 'graph.dtd');

// Creates a DOMDocument instance
$dom = $imp->createDocument("", "", $dtd);

// Set other properties
$dom->encoding = 'UTF-8';
$dom->standalone = false;

// Create an empty element
$element = $dom->createElement('graph');

// Append the element
$dom->appendChild($element);

// Retrieve and print the document
echo $dom->saveXML();

?>
代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE graph SYSTEM "graph.dtd">
<graph/>

扫码关注腾讯云开发者

领取腾讯云代金券