如何为此 xml 创建 dtd?
我被要求为这个 xml 创建一个简单的 dtd :
<?xml version='1.0' encoding='ISO-8859-1'?>
<QUERY>
<PORT>
<NB></NB>
</PORT>
<BLOCK>
<TAB></TAB>
</BLOCK>
<STAND>
<LEVEL></LEVEL>
</STAND>
</QUERY>
我正在使用 java,我以前从未做过 dtd,也不知道它到底是什么意思。 如果可能的话,我想要一些指导,谢谢
i have been asked to create a simple dtd for this xml :
<?xml version='1.0' encoding='ISO-8859-1'?>
<QUERY>
<PORT>
<NB></NB>
</PORT>
<BLOCK>
<TAB></TAB>
</BLOCK>
<STAND>
<LEVEL></LEVEL>
</STAND>
</QUERY>
i am using java, i've never did dtd before nor do i know precisely what does it mean.
i would like some guidance if its possible, thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
DTD 是文档类型定义,用于表示 XML 文档的结构。其他表示形式包括 XML Schema、Relax NG 等:
它将如下所示(尽管我的语法可能不太正确):
如果您查看 QUERY 的定义,您会发现它定义了它包含以下元素:“PORT”、“BLOCK”和“站立”。如果您查看 NB 的定义,我们已经声明它应该包含文本(已解析的字符数据)。
DTD is Document Type Definition, and is used to represent the structure of you XML document. Other representations include XML Schema, Relax NG, etc.:
It will look something like the following (although my syntax may not be quite right):
If you look at the definition for QUERY you see it defines that it contains the elements: "PORT", "BLOCK", and "STAND". If you look at the definition for NB, we have declared that it should contain text (parsed character data).
XMLBeans 附带一个名为
inst2xsd
它可以检查 XML 文件并为其创建一个 XSD,然后您可以对其进行编辑/优化。我用过它,效果非常好。只需阅读 XMLBeans 安装指南,当您安装 XMLBeans 时,您将获得
inst2xsd
工具也已安装。编辑 - 刚刚意识到您想要一个 DTD 而不是 XSD,将其留在这里以防 XSD(用途非常相似)实际上可以解决您的问题
XMLBeans comes with a tool called
inst2xsd
which can inspect an XML file and create an XSD for it that you can then edit/refine. I've used it with pretty good results.Just read the installation guide for XMLBeans and when you install XMLBeans you'll have the
inst2xsd
tool installed as well.edit - just realized you wanted a DTD and not an XSD, leaving this here in case an XSD (which is very similar in purpose) could actually solve your problem anyway
那里有一些 DTD 生成器。快速搜索会产生这个。不过还没用过。
There are some DTD generators out there. Quick search yields this. Haven't used it, though.