XML file with DTD displays fine in web browser after invalid change

浪尽此生 提交于 2019-12-11 02:59:46

问题


I am new to XML and DTD. I have written an XML file with DTD. Here is it.

<?xml version="1.0"?>
<!DOCTYPE  note[
     <!ELEMENT note (page , author ,company)>
     <!ELEMENT page (#PCDATA)>
     <!ELEMENT author (#PCDATA)>
     <!ELEMENT company (#PCDATA)>
     <!ATTLIST note type CDATA #IMPLIED>
]>

<note typ="single">
    <page>1000</page>
    <author>devan</author>
    <author>devan</author>
    <company>IDM</company>
</note>

It works fine. But my problem is, if you set the note attribute as typ it displays the result in the web browser just fine. But in the DTD it defines <!ATTLIST note type CDATA #IMPLIED>.

And whenever I change the tags in xml <pag>fhdh </pag> it displays in the web browser just fine. My problem is then why do we define DTD?


回答1:


DTD by itself only defines what a valid XML looks like.

If you run the sample XML in the question through an XML validator, it will not be considered valid for the DTD you specified in the question.




回答2:


Here are some reasons ...

http://csharpcomputing.com/XMLTutorial/Lesson8.htm

http://www.htmlbasictutor.ca/doctype-declaration.htm

And a PDF: DTD for XML



来源:https://stackoverflow.com/questions/7061577/xml-file-with-dtd-displays-fine-in-web-browser-after-invalid-change

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!