PHP XML validation using DOMDocument with internally specified schema URI - "No DTD found!"

Viewed 19

The xml document quoted in the following code validates using several on-line services:

libxml_use_internal_errors();

$xml = '<?xml version="1.0" encoding="utf-8"?>
<TEI xmlns="http://www.tei-c.org/ns/1.0">
<teiHeader> <fileDesc> <titleStmt> <title/> <author/> </titleStmt>
<publicationStmt> <publisher /> </publicationStmt>
</fileDesc> </teiHeader>
<text>
<body>
<div type="section"><p><label>BLAZE</label>,
a white spot in a horse’s face.</p></div></body></text></TEI>';

$doc = new DOMDocument;
$doc->loadXML($xml);

if($doc->validate()) {
    echo "Looks good.";
}
else {
    var_dump(libxml_get_errors());
}

Sadly, I get the message "Warning: DOMDocument::validate(): no DTD found!"

What to do?

1 Answers

According to the TEI itself,

A TEI SGML document must begin with a document type definition (DTD), as must a valid TEI XML document (though not a merely well-formed TEI XML document). Local systems may allow the DTD to be implicit, but for interchange purposes it must be explicit for both SGML and XML. Because of its highly modular nature, it may in any case be desirable for the component parts of the TEI DTD to be made explicit even for local processing.

I believe this is connected to a point made in the link @scuzzy posted:

As of 2009, newer XML namespace-aware schema languages (such as W3C XML Schema and ISO RELAX NG) have largely superseded DTDs.

Related