使用 RNOM 从 RelaxNG 模式生成对象模型 - 如何开始?

发布于 2024-12-07 15:08:58 字数 690 浏览 0 评论 0原文

我想从 RelaxNG 架构中生成对象模型。

因此我想使用 RNGOM 对象模型/解析器 (主要是因为我找不到任何替代方案 - 尽管我甚至不关心解析器编写/生成的语言)。现在我从 SVN 查看了 RNGOM 源,我不知道如何使用 RNOM,因为没有任何有关其用法的信息。

如何开始使用 RNOM 的有用提示 - 链接、示例或任何描述,使我不必阅读理解 RNOM 的整个源代码 - 将被视为答案。 更好的是如何使用解析器从 RNG 文件生成对象模型的简单示例。

更多信息:

我想根据以下 RelaxNG 架构生成 Java 类:
http://libvirt.org/ git/?p=libvirt.git;a=tree;f=docs/schemas;hb=HEAD

我发现 Glassfish 的人正在使用 rngom 来生成我需要的相同对象模型,但我还不能查出他们如何使用 rngom。

I want to generate an object model out of an RelaxNG Schema.

Therefore I want to use the RNGOM Object Model/Parser (mainly because I could not find any alternative - although I don't even care about the language the parser is written in/generates). Now that I checked out the RNGOM source from SVN, I don't have ANY idea how to use RNGOM, since there is not any piece of information out there about the usage.

A useful hint how to start with RNGOM - a link, example, or any description which saves me from having to read understand the whole source code of RNGOM - will be awarded as an answer.
Even better would be a simple example how to use the parser to generate an Object model out of an RNG file.

More infos:

I want to generate Java classes out of the following RelaxNG Schema:
http://libvirt.org/git/?p=libvirt.git;a=tree;f=docs/schemas;hb=HEAD

I found out that the Glassfish guys are using rngom to generate the same object model I need, but I could not yet find out how they are using rngom.

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

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

发布评论

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

评论(2

南笙 2024-12-14 15:08:58

继续的方法可能是:

  1. 使用 jing 从 Relax NG 转换为 XML Schema(参见此处< /a>)
  2. 使用更常见的工具来生成类(例如JaxB)。

A way to proceed could be to :

  1. use jing to convert from Relax NG to XML Schema (see here)
  2. use more common tools to generate classes (e.g. JaxB).
只想待在家 2024-12-14 15:08:58

您好,除了我专注于紧凑语法之外,我遇到了几乎相同的要求。这是做你想做的事情的一种方法,但YMMV。

为了提供一些背景信息,我的目标分为两个阶段:(a) 尝试使用 RelaxNG Compact Syntax 并遍历对象/树来创建可在 Spring 4 Rest Controller 中使用的 Spring 4 POJO。 (b) 从那里我想开发一个请求验证器,它使用 RNG Compact 并在 Spring 反序列化请求之前自动验证请求。基本上使用 RelaxNG Compact Syntax 作为设计/文档和 JSON 模式定义/验证来构建 JSON REST API 开发。

对于第一个目标,我考虑使用 JJTree 来注释 CompactSyntax,但我显然对 JavaCC 不太熟悉,所以我决定采用一种更加编程的方法...

我以多种方式分析和测试了代码,以确定是否存在树实现二进制、消化和/或 nc 包,但我认为不存在这样的包(om/树)。

因此,我最新的、实际上成功的方法是基于二进制文件并扩展 SchemaBuilderImpl,实现访问者接口,并使用长构造函数将我的自定义 SchemaBuilderImpl 传递给 CompactSyntax:CompactSyntax(CompactParseable parseable, Reader r, String sourceUri, SchemaBuilder sb, ErrorHandler嗯,String继承Ns)

当您调用CompactParseable.parse时,您将在访问者界面中获得结构化事件,我认为这足以遍历rng 模式,从这里您可以轻松创建 OM 或树。

但我不确定这是最好的方法。也许我错过了一些东西,实际上有一个由 rngom 实现(在我的例子中为 CompactSyntax)构建的 OM/Tree,您可以遍历它来更轻松地确定父/子关系。或者也许还有其他方法可以实现这一点。

不管怎样,这似乎是一种适合我想要的方法。主要是基于访问者模式,并且由于接口在那里,所以我决定使用它们。也许它对你有用。最重要的是,我找不到可以在实现包(nc、二进制、摘要)中的任何位置遍历实现的 OM/AST。

Hi I ran into mostly the same requirement except I am concentrating on the Compact Syntax. Here is one way of doing what you want but YMMV.

To give some context, my goal in 2 phases: (a) Trying to slurp RelaxNG Compact Syntax and traverse an object/tree to create Spring 4 POJOs usable in Spring 4 Rest Controller. (b) From there I want to develop a request validator that uses the RNG Compact and automatically validates the request before Spring de-serializes the request. Basically scaffolding JSON REST API development using RelaxNG Compact Syntax as both design/documentation and JSON schema definition/validation.

For the first objective I thought about annotating the CompactSyntax with JJTree but I am obviously not fluent in JavaCC so I decided to go a more programatic approach...

I analyzed and tested the code in several ways to determine if there was a tree implementation in binary, digested and/or nc packages but I don't think there is one (an om/tree) as such.

So my latest, actually successful approach, has been to build upon binary and extend SchemaBuilderImpl, implement the visitor interface, and passing my custom SchemaBuilderImpl to CompactSyntax using the long constructor: CompactSyntax(CompactParseable parseable, Reader r, String sourceUri, SchemaBuilder sb, ErrorHandler eh, String inheritedNs)

When you call CompactParseable.parse you will get structured events in the visitor interface and I think this is good enough to traverse the rng schema and from here you could easily create an OM or tree.

But I am not sure this is the best approach. Maybe I missed something and there is in fact an OM/Tree built by the rngom implementation (in my case CompactSyntax) that you can traverse to determine parent/child relationships more easily. Or maybe there are other approaches to this.

Anyway, this is one approach that seems to be working for what I want. Is mostly visitor pattern based and since the interfaces were there I decided to use them. Maybe it will work for you. Bottom line, I could not find an OM/AST that can be traversed implemented anywhere in the implementation packages (nc, binary, digested).

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