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.DOMImplementation::createDocumentType
Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.
DOMImplementation::createDocumentType
Референца за `domimplementation.createdocumenttype.php` со подобрена типографија и навигација.
DOMImplementation::createDocumentType
класата mysqli_driver
DOMImplementation::createDocumentType — Creates an empty DOMDocumentType object
= NULL
$qualifiedName, string $publicId = "", string $systemId = ""): DOMDocumentType|falseCreates an empty DOMDocumentType object. Entity declarations and notations are not made available. Entity reference expansions and default attribute additions do not occur.
Параметри
qualifiedName-
Квалификуваното име на типот на документ што треба да се креира.
publicId-
Јавниот идентификатор на надворешниот подмножество.
systemId-
Системскиот идентификатор на надворешниот подмножество.
Вратени вредности
Нов DOMDocumentType node with its
ownerDocument постави на null or false при грешка.
Errors/Exceptions
Може да фрли DOMException со следните кодови за грешки:
DOM_NAMESPACE_ERR-
Raised if there is an error with the namespace, as determined by
qualifiedName.
Дневник на промени
| Верзија | = NULL |
|---|---|
| 8.0.0 |
Повикувањето на оваа функција статички сега ќе фрли Грешка. Претходно, а E_DEPRECATED беше кренат.
|
Примери
Example #1 Creating a document with an attached DTD
<?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();
?>Пример #1 Пример што покажува затворачка ознака што го опфаќа последниот нов ред
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE graph SYSTEM "graph.dtd"> <graph/>
Види Исто така
- XSLTProcessor::importStyleSheet() - Создава DOMDocument објект од наведениот тип со неговиот документ елемент