问题
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