简体   繁体   English

参考外部DTD文件

[英]Reference External DTD file

I have an XML file, CSS File and a DTD file. 我有一个XML文件,CSS文件和一个DTD文件。 I expect that when my reference to the dtd file is invalid ie add zzz to the name as shown below in the xml file that an error would be raised when i try to open in google Chrome. 我希望当我对dtd文件的引用无效时,即将zzz添加到名称中,如下面xml文件中所示,当我尝试在Google Chrome中打开时会出现错误。 I don not get an error?. 我没有收到错误? The same applies if I edit the dtd file and add the text zzz to the word Body (As shown) - it should give me an error when opening the xml file. 如果我编辑dtd文件并将文本zzz添加到单词Body(如图所示),则同样适用 - 打开xml文件时应该给我一个错误。 Am i missing something ? 我错过了什么吗? All files are in the same directory. 所有文件都在同一目录中。 The css file works perfect. css文件非常完美。

XML File XML文件

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<?xml-stylesheet type="text/css" href="Style.css"?>
<!DOCTYPE Main SYSTEM "Definitionzzz.dtd">
<Main xmlns:html="http://www.w3.org/1999/xhtml">
<Heading>
Important text  
</Heading>
<Newline></Newline>
<Body>
Important text
</Body>
<Newline></Newline>
<Heading>
Important text  
</Heading>
<Newline></Newline>
<Body>
Important text  
</Body>
<Newline></Newline>
</Main>

DTD File DTD文件

<!--DTD syntax-->
<!DOCTYPE Main
[
<!ELEMENT Main (Heading,Body,Newline,Bullet)>
<!ELEMENT Heading (#PCDATA)>
<!ELEMENT Bodyzzz (#PCDATA)>
<!ELEMENT Newline (#PCDATA)>
<!ELEMENT Bullet (#PCDATA)>
]>

CSS File CSS文件

/* CSS For headings */
Main
{
    border-radius: 5px; 
    padding: 0;
    margin: 0;
    position: absolute; 
    top: 15px;
    left: 15px;
    right: 15px;
    bottom: 15px;
    overflow: auto;
}
Heading
{
    color: #000000;
    font-size: 20pt;
    text-align: center;
    margin-left:15px;
    text-decoration:underline;
}
/* CSS For Body */
Body
{
    color: #000000;
    font-size: 10pt;

}
/* CSS For Bullets */
Bullet
{
    color: #000000;
    font-size: 15pt;
    list-style-type: bullet;
    left: 30px;
    margin-left:30px;
}
/* CSS For Making a new line */
Newline
{
    display:block
}
/* CSS For Weblinks */
a:link:after, a:visited:after
{
content:attr(href); /*displays the actual URL*/
font-size:20pt;
display:block; /*show URLs on a separate line*/
}

Web browsers do not do markup validation, beyond checking that XML is well-formed (that is, it is XML at all). 除了检查XML是否格式正确 (即,它完全是XML)之外,Web浏览器不进行标记验证。 They do not even read DTDs. 他们甚至不读DTD。

To validate an XML document, you need an XML validator. 要验证XML文档,您需要一个XML验证器。 One clumsy possibility is the W3C Markup Validator . 一个笨拙的可能性是W3C标记验证器 Even though it is in many ways HTML oriented, it has an SGML and XML validator as the basis, and you can use it on XML documents. 虽然它在很多方面都是面向HTML的,但它有一个SGML和XML验证器作为基础,你可以在XML文档上使用它。 You would need to put the DTD on a web server so that it can be referred to by URL, or include it in the XML document. 您需要将DTD放在Web服务器上,以便可以通过URL引用它,或将其包含在XML文档中。 Note that an external DTD file should not have a <!DOCTYPE Main [...]> wrapper around the declarations, as it only belongs to a case where the DTD is embedded in the XML document, eg 请注意,外部DTD文件不应该在声明周围包含<!DOCTYPE Main [...]>包装器,因为它只属于DTD嵌入在XML文档中的情况,例如

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<?xml-stylesheet type="text/css" href="Style.css"?>
<!DOCTYPE Main
[
<!ELEMENT Main (Heading,Body,Newline,Bullet)>
<!ELEMENT Heading (#PCDATA)>
<!ELEMENT Bodyzzz (#PCDATA)>
<!ELEMENT Newline (#PCDATA)>
<!ELEMENT Bullet (#PCDATA)>
]>
<Main xmlns:html="http://www.w3.org/1999/xhtml">
...

By the way, even without the zzz , the document is invalid – your DTD declares a structure that has four specific elements as children of the root element, in the specified order, and without any repetition. 顺便说一下,即使没有zzz ,文档也是无效的 - 您的DTD声明了一个结构,该结构具有四个特定元素作为根元素的子元素,按指定的顺序,并且没有任何重复。

Follow this tutorial... https://gist.github.com/Squiva/7c1a0f98c3fe820f640d You can also do this... Where node is the name of your main node, and Foobar.dtd is the path to your DTD file. 按照本教程... https://gist.github.com/Squiva/7c1a0f98c3fe820f640d您也可以这样做...其中node是主节点的名称,Foobar.dtd是DTD文件的路径。 Enjoy your Document Type Definitions. 享受您的文档类型定义。

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

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