Validation of an xml document using a dtd document

你离开我真会死。 提交于 2019-12-31 03:12:10

问题


I'm new to XML. I'm confused how a DTD document validates an XML document. Below is my code and please correct me if I am wrong.

<?xml version="1.0" encoding="iso-8859-1"?>

<!DOCTYPE note  
[
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>

<note>
<to>Tove</to>

<rom>Jani</rom> // Here i've miss-spelled the tag <from> but still not getting error

<heading>Reminder</heading>
<body>Don't forget me this weekend!</body> 
</note>

I know that a DTD is used to validate the XML data. There is an element name <form>. I've just changed the spelling of <form> to <rom> but still did not get any error message in my browser. I'm stuck at this point.


回答1:


Welcome to the XML community.

You will need to find and use a validating parser for your XML; if you want to use a Web browser, you may be disappointed. Older versions of Internet Explorer validate XML against a DTD by default; newer versions don't (but I believe that you can configure them to do so if you can figure out how). Mozilla-based browsers don't have a validating XML parser at all.

Most people who use XML seriously end up using XML-specific tools for validation. Among my favorites for command-line validation are

  • xmllint (the command-line interface to libxml2, which is part of the Gnome project but is also usable outside Gnome)

  • rxp (by Richard Tobin of the University of Edinburgh)

  • Xerces J, Xerces C (these are Apache projects)

There are also XML-aware editors which offer integrated validation from within the editor (sometimes from your choice of several parsers).



来源:https://stackoverflow.com/questions/14014307/validation-of-an-xml-document-using-a-dtd-document

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