xml 中的 DTD 如何使使用 java DOM 更容易解析?

发布于 2024-10-27 09:05:24 字数 280 浏览 1 评论 0原文

嘿朋友们, 我被分配了一个查询规划项目。 在这个项目中,如果输入类似 sql 的查询,我必须对其进行切片并转换为 xml。 我做了这一部分,但是我需要为此 xml 添加 DTD,因为正如项目提到的那样,它有助于解析(使用 java DOM)此查询并轻松找到选择 - 查询中指定的重复和联接。

我不明白,在使用 DOM 解析 xml 并找到该 xml 的不同部分时,DTD 如何提供帮助?

我可以使用 DOM 来查找 xml 的不同部分,而无需 dtd...任何人都可以给我提供差异的示例吗?

谢谢

hey friends,
i have been assigned a query planning project.
in this project if enter an sql like query, which i have to slice and turn into an xml.
i did this part, however i am required to add a DTD for this xml, because as the project mentions it helps to parse (using java DOM) this query and find easily the selection - duplicates and joins specified in the query.

i don't understand, how does a DTD help while using DOM to parse the xml and find the different parts of this xml?

i could use DOM to find the different parts of the xml without a dtd... Can anybody give me and example of the difference?

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

注定孤独终老 2024-11-03 09:05:24

DTD 告诉解析器哪些标签是允许的,以及它们应该出现在文档中的什么位置。如果没有 DTD,解析器将读取标签,但不知道该标签是否是预期的标签,或者它是否位于正确的位置。

如果您使用 SAX 或 DOM 解析 XML,这并不重要,如果没有 DTD(或者最近的替代品之一,如 XSD、RelaxNG 等),解析器都不会知道您的标记是预期的还是意外的。

A DTD tells the parser which tags are allowed, and where in the document they should be expected. Without a DTD, the parser will read the tags but it won't know if the tag was an expected one, or if it was in the right place.

If you parse your XML with SAX or DOM, it doesn't matter, neither parser will know if your tags are expected or unexpected without a DTD (or one of it's more recent replacements like XSD, RelaxNG, etc).

错々过的事 2024-11-03 09:05:24

DTD 不帮助解析 XML,但它通过定义有关文档的某些规则来提供基本验证。如果文档违反验证规则,则解析应该失败(或生成警告消息,这应该取决于验证器配置)。他们可能称其“有用”,因为您的 DOM 导航代码将能够对文档的结构做出更好的假设,而不必担心不恰当的失败。

他们可能希望您包含 DTD,因为否则必须从 PUBLIC/SYSTEM 文档标识符识别 DTD,并将其托管在某处。或者他们应该在源代码中具有预定义的 DTD(也是“托管某处”的一个版本),如果相同的代码必须在不事先了解结构的情况下处理不同的文档,则这可能不是一个选项。

关于更容易查找重复项的说法可能是因为他们计划在出现​​重复项时将其丢弃;在不了解切片和车削细节的情况下,不确定它对连接有多大帮助。

DTD does not help to parse the XML, but it provides a rudimentary validation by defining certain rules about the document. If the document violates the validation rules, the parsing should fail (or produce a warning message, that should depend on the validators configuration). They may call it "helpful", because your DOM navigation code would be able to make better assumptions about the structure of the document, without fear of ungraceful failure.

They probably want you to include the DTD because otherwise the DTD has to be recognized from PUBLIC/SYSTEM document identifier, and be hosted somewhere. Or they should have a predefined DTD in the source code(also a version of this "hosting somewhere"), which may not be an option if the same code has to process different documents without prior knowledge to the structure.

The statement about finding duplicates easier may be because they plan to throw the document out in case of a duplicate; not sure how helpful it is for the joins, not without knowing the details of the slicing and turning.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文