简体   繁体   English

给定参考外部dtd文件,xml文件不报告错误

[英]xml file does not report error, given a reference external dtd file

I have written a dtd file to regulate a xml file, but when wrote something wrong according to definition in the dtd file, I found no any errors exported by Eclipse. 我已经写了一个dtd文件来管理xml文件,但是当根据dtd文件中的定义写错了什么时,我发现Eclipse没有导出任何错误。 I reviewed many times on both files but found no mistake by myself. 我对这两个文件进行了多次审查,但我自己没有发现任何错误。 Below are the 2 simple files. 以下是2个简单文件。 Could anybody help to figure out what I am missing or the reason why no error reported? 有人可以帮我弄清楚我所缺少的内容还是没有错误报告的原因吗? Thanks in advance. 提前致谢。

Here is the dtd file, 这是dtd文件,

<?xml version="1.0" encoding="UTF-8"?>
<--!no classNo or one classNo at most, at least one teacher-->
<!DOCTYPE school [
    <!ELEMENT school (class)>
    <!ELEMENT class (classNo?,teacher+)>
    <!ElEMENT classNo (#PCDATA)> 
    <!ElEMENT teacher (#PCDATA)>
]>

Here is the xml file, 这是xml文件,

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE school SYSTEM "Teacher.dtd">

<school>
    <class>
        <classNo>Class 3</classNo>
        <teacher>Mary</teacher>
    </class>
</school>

If I add another classNo Element, no error reported. 如果我添加另一个classNo Element,则没有错误报告。 The xml file and dtd file are in the same package in Eclipse. xml文件和dtd文件在Eclipse中位于同一软件包中。

The DTD is ill-formed. DTD格式错误。 The DOCTYPE declaration should only be in the XML document, not in the DTD. DOCTYPE声明应仅在XML文档中,而不在DTD中。 There are a couple of typos as well (lower-case "l" instead of upper-case "L"; --! in the comment should be !-- ). 还有一些错别字(小写的“ l”代替大写的“ L”; --!在注释中应该是!-- )。

The XML document validates against this DTD: XML文档根据此DTD进行验证:

<!ELEMENT school (class)>
<!ELEMENT class (classNo?,teacher+)>
<!ELEMENT classNo (#PCDATA)> 
<!ELEMENT teacher (#PCDATA)>

You also have to make sure that validation is enabled in Eclipse of course (assuming that XML Editors and Tools is installed). 当然,您还必须确保在Eclipse中启用了验证(假设已安装XML编辑器和工具)。

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

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