简体   繁体   English

PHP XML 使用带有内部指定架构 URI 的 DOMDocument 进行验证 - “未找到 DTD!”

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

The xml document quoted in the following code validates using several on-line services:以下代码中引用的 xml 文档使用多个在线服务进行验证:

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!"遗憾的是,我收到消息“警告:DOMDocument::validate():未找到 DTD!”

What to do?该怎么办?

According to the TEI itself,根据 TEI 本身,

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). TEI SGML 文档必须以文档类型定义 (DTD) 开头,有效的 TEI XML 文档也必须开始(尽管不仅仅是格式正确的 TEI XML 文档)。 Local systems may allow the DTD to be implicit, but for interchange purposes it must be explicit for both SGML and XML.本地系统可能允许 DTD 是隐式的,但出于交换目的,对于 SGML 和 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.由于其高度模块化的性质,在任何情况下都可能希望 TEI DTD 的组成部分即使对于本地处理也是明确的。

I believe this is connected to a point made in the link @scuzzy posted:我相信这与@scuzzy 发布的链接中的一点有关:

As of 2009, newer XML namespace-aware schema languages (such as W3C XML Schema and ISO RELAX NG) have largely superseded DTDs.截至 2009 年,较新的 XML 命名空间感知模式语言(例如 W3C XML Schema 和 ISO RELAX NG)已在很大程度上取代了 DTD。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM