Generate an object model from RelaxNG schema using RNGOM - how to get started?

I want to create an object model from the RelaxNG schema.

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

A useful hint on how to start with RNGOM - a link, for example, or any description that saves me from having to read all the source code of RNGOM will be given as an answer. Even better would be a simple example of using a parser to generate an object model from an RNG file.

Additional Information:

I want to create Java classes from the following RelaxNG schema:
http://libvirt.org/git/?p=libvirt.git;a=tree;f=docs/schemas;hb=HEAD

I found out that Glassfish guys use rngom to create the exact same object model that I need, but I still could not find out how they use rngom.

+6
source share
2 answers

The continuation method may consist of the following:

  • use jing to convert from Relax NG to XML Schema ( see here )
  • use more common class generation tools (e.g. JaxB).
+3
source

Hi, I came across the same requirement, except that I focus on compact syntax. Here is one way to do what you want, but YMMV.

To give some context, my goal is in 2 steps: (a) Trying to smooth out RelaxNG Compact Syntax and go through the object / tree to create the Spring 4 POJOs used in the Spring 4 Rest Controller. (b) From there, I want to develop a query validator that uses RNG Compact and automatically validates the request before Spring de-serializes the request. Mostly JSON REST API scaffold development using RelaxNG Compact Syntax for both design and documentation and definition / validation of JSON schemas.

For the first purpose, I thought about annotating CompactSyntax with JJTree, but I obviously do not own JavaCC, so I decided to move on to a more programmatic 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 (om / tree) as such.

So my last really successful approach was to build on a binary code and extend SchemaBuilderImpl, implement a visitor interface and pass my own SchemaBuilderImpl to CompactSyntax using a long constructor: CompactSyntax (CompactParseable parseable, Reader r, String sourceUri, SchemaBuilder sb, ErrorHandler eh, String inheritedNs)

When you call CompactParseable.parse, you get structured events in the visitor interface, and I think it is good enough to cross the rng diagram, and from here you can easily create an OM or tree.

But I'm not sure if this is the best approach. Maybe I missed something, and there really is an OM / Tree created by the rngom implementation (in my case CompactSyntax) that you can traverse to more easily define the relationship between parents and children. Or maybe there are other approaches to this.

Anyway, this is one approach that seems to work for what I want. It is mainly a visitor template, and since the interfaces were there, I decided to use them. Maybe this will work for you. In the bottom line, I could not find OM / AST, which can be traversed implemented anywhere in the implementation packages (nc, binary, digested).

0
source

Source: https://habr.com/ru/post/898353/


All Articles