是否可以将 groovy.xml.MarkupBuilder 与给定的 DTD 一起使用?

发布于 2024-10-01 03:41:58 字数 370 浏览 1 评论 0 原文

这个问题总结得很好,无论如何,多余的细节从来都不是多余的。

我想使用 Apache Forrest 文档/groovy/xml/MarkupBuilder.html" rel="nofollow">groovy.xml.MarkupBuilder. 我显然希望我的文档不仅格式良好,而且根据 Forrest DTD。我怎样才能确保这一点?

The question sums it up quite well, anyway, superfluous details are never that superfluous.

I want to create Apache Forrest documents using groovy.xml.MarkupBuilder. I obviously want my documents to be not only well-formed, but also valid according to Forrest DTD. How can I ensure that ?

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

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

发布评论

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

评论(1

有木有妳兜一样 2024-10-08 03:41:58

好问题。 AFAIK,唯一的方法是在生成节点后根据 DTD 验证 XML。通常,这将通过单独的过程进行。请参阅本文了解如何在 Java 中执行此操作(取决于哪个版本)。

但需要澄清的是:鉴于您完全控制生成 XML,您希望 MarkupBuilder 如何帮助确保有效性...如果您尝试创建在特定点不允许的节点,则抛出异常? 不完整的 XML 文档的有效性不是一个明确定义的概念。如果无效性是缺少必需的元素怎么办...当您创建其父节点时,其子节点都将“丢失” ,那么 MarkupBuilder 如何知道何时判定 XML 无效呢?或者,如果您发出 ID 或 IDREF 类型的属性,并且在发出所有其他 ID 之前无法检查唯一性或引用完整性,该怎么办?

我无法想象有一个流程能够真正保证有效的 XML 输出,这与生成输出后对其进行验证有很大不同。

肯定有一些方法可以在输出期间部分进行验证,即捕获一些可能导致无效输出的问题。

然而,模式感知 XSLT 显然可以在 XML 生成期间完成完整的验证。文章位于 http://www.ibm.com/developerworks/ xml/library/x-schemaxslt.html#validout 讨论使用架构感知 XSLT 转换来保证输出有效。我完全不确定这是如何运作的。也许它会在生成过程中验证它可以做什么,但对于某些限制,它必须等到输出完成才能宣布它有效或无效。

这并没有回答您关于 Groovy MarkupBuilder 的问题,但它揭示了可能性。 AFAIK,没有免费的 XSLT 处理器提供模式感知处理;但 Saxon-SA 有 30 天的试用期,其他商业产品可能也是如此。

Good question. AFAIK, the only way is to validate your XML against the DTD after the nodes are generated. Typically this would be by a separate process. See this article for how to do that in Java (depending on which version).

But to clarify: given that you are in full control of generating the XML, how do you want MarkupBuilder to help ensure validity ... throw an exception if you try to create a node that's not allowed at a particular point? Validity of an incomplete XML document is not a well-defined concept. What if the invalidity is that a required element is missing... when you create its parent node, its children will all be "missing", so how would MarkupBuilder know when to decide the XML is invalid? Or what if you emit an attribute of type ID or IDREF, and you can't check for uniqueness or referential integrity until all other IDs are emitted?

I can't imagine a process that would really work for guaranteeing valid XML output, that is significantly different from validating the output after it's generated.

There are definitely ways to partially validate during output, i.e. to catch some problems that would lead to invalid output.

However, Schema-aware XSLT apparently can do complete validation during generation of the XML. The article at http://www.ibm.com/developerworks/xml/library/x-schemaxslt.html#validout talks about using Schema-aware XSLT transformations to guarantee that the output is valid. I'm not sure entirely how that works. Maybe it validates what it can during generation, but for some constraints it has to wait till the output is finished before pronouncing it valid or not.

That doesn't answer your question about Groovy MarkupBuilder, but it sheds light on what is possible. AFAIK, there are no free XSLT processors that provide schema-aware processing; but Saxon-SA has a 30-day trial, and probably other commercial ones do too.

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