DOMImplementation::createDocumentType

(PHP 5, PHP 7, PHP 8)

DOMImplementation::createDocumentTypeBoş bir DOMDocumentType nesnesi oluşturur

Açıklama

public DOMImplementation::createDocumentType(string $belgeAdı, string $publicId = "", string $systemId = ""): DOMDocumentType|false

Boş bir DOMDocumentType nesnesi oluşturur. Öğe bildirimleri ve gösterimler kullanılabilir değildir. Öğe gönderimi dönüşümleri ve öntanımlı öznitelik eklemeleri yapılmaz.

Bağımsız Değişkenler

belgeAdı

Oluşturulacak belgenin nitelikli adı.

publicId

Harici alt kümenin genel betimleyicisi.

systemId

Harici alt kümenin sistem betimleyicisi.

Dönen Değerler

ownerDocument özelliği null olmak üzere yeni bir DOMDocumentType nesnesi döner. Başarısızlık durumunda false döner.

Hatalar/İstisnalar

DOM_NAMESPACE_ERR

belgeAdı ile belirlenen isim alanı ile ilgili bir hata varsa bu hata oluşur.

Sürüm Bilgisi

Sürüm: Açıklama
8.0.0 Bu işlevin duruk olarak çağrılması artık Error oluşturuyor. Evvelce E_DEPRECATED hatası verirdi.

Örnekler

Örnek 1 - Bir DTD ekleyerek bir belge oluşturmak

<?php

// Yeni bir DOMImplementation nesnesi oluşturalım
$imp = new DOMImplementation;

// Bir DOMDocumentType nesnesi oluşturalım
$dtd = $imp->createDocumentType('graph', '', 'graph.dtd');

// Bir DOMDocument nesnesi oluşturalım
$dom = $imp->createDocument("", "", $dtd);

// Diğer özellikleri tanımlayalım
$dom->encoding = 'UTF-8';
$dom->standalone = false;

// Boş bir eleman oluşturalım
$element = $dom->createElement('graph');

// Bir eleman ekleyelim
$dom->appendChild($element);

// Belgeyi çıktılayalım
echo $dom->saveXML();

?>

Yukarıdaki örneğin çıktısı:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE graph SYSTEM "graph.dtd">
<graph/>

Ayrıca Bakınız

add a note

User Contributed Notes 1 note

up
0
until-all-bytes-are-free at example dot org
12 years ago
I had problems to use a DTD from a file. It needed to be resolved relatively and it contained characters that made DomDocument failed to resolve the file.

Encoding and an absolute filename did not help much. So I used the data:// streamwrapper ( http://php.net/manual/en/wrappers.data.php ) as a work-around:

<?php

// relative or absolute filename
$path = '...';

// convert file contents into a filename
$data = file_get_contents($path);
$systemId = 'data://text/plain;base64,'.base64_encode($data);

// ...

// Creates a DOMDocumentType instance
$dtd = $aImp->createDocumentType('qualified name', '', $systemId);

?>

Works like a charm.
To Top