使用DTD文档验证XML文档 [英] Validation of an xml document using a dtd document
问题描述
我是XML的新手。我对DTD文档如何验证XML文档感到困惑。下面是我的代码,如果我错了,请纠正我。
<?xml version = 1.0 encoding = iso -8859-1?>
<!DOCTYPE注释
[
<!ELEMENT注释(至,来自,标题,正文)>
<!ELEMENT to(#PCDATA)>
<!ELEMENT from(#PCDATA)>
<!ELEMENT标题(#PCDATA)>
<!ELEMENT正文(#PCDATA)>
]>
< note>
< to> Tove< / to>
< rom> Jani< / rom> //在这里,我拼写了< from>标签的拼写错误但仍未收到错误
< heading>提醒< / heading>
< body>这个周末别忘了我!< / body>
< / note>
我知道DDT用于验证XML数据。有一个元素名称< form>
。我刚刚将< form>
的拼写更改为< rom>
,但仍然没有得到任何错误我的浏览器中显示消息。我被困在这一点上。
欢迎使用XML社区。 p>
您需要为您的XML查找并使用验证解析器;如果您想使用Web浏览器,可能会感到失望。默认情况下,较旧版本的Internet Explorer会针对DTD验证XML;较新的版本则没有(但我相信您可以配置它们,如果可以的话)。基于Mozilla的浏览器根本没有验证XML解析器。
大多数使用XML的人最终都会使用特定于XML的工具进行验证。在我最喜欢的命令行验证中,
-
xmllint(libxml2的命令行界面,它是Gnome的一部分)项目,但也可以在Gnome之外使用)
-
rxp(由爱丁堡大学的Richard Tobin提供)
-
Xerces J,Xerces C(这些是Apache项目)
也有支持XML的编辑器可以在编辑器中提供集成的验证功能(有时需要您选择多个解析器)。
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.
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).
这篇关于使用DTD文档验证XML文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!