ODF XML Reference HTML: Using some short notation for relationship of node children #184
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem: Making "child relations" of ODF grammar evident for ODF Reference
I wanted to do this for more than 10 years, even the latest ODF 1.3 specification still omits the relationship of child nodes (sequence, choice, optional in their listings), see for instance:
from https://docs.oasis-open.org/office/OpenDocument/v1.3/os/part3-schema/OpenDocument-v1.3-os-part3-schema.html#element-form_property
You still need to look into the RNG (at least now in HTML since ODF 1.3) to understand the constraints!
Instead, in the future, the relations of the child nodes should become more evident (here with a screenshot from the generated text - no layout in HTML yet) ->
taken from https://tdf.github.io/odftoolkit/odf1.3/OpenDocument-v1.3-reference__TestChildRelations.html#element_form:property_1 (and text manually formatted)
Solution Overview
Status
This work on this ODF Toolkit branch is still in progress and this is an intermediate pull-request to receive feed-back!
Building/Testing the Solution
Code prefixes were completely irrelevant and were added by the branch namespace-prefix2 you need to clone
git clone -b namespace-prefix2 https://github.com/xmlark/msv
mvn install
Afterwards the JAR will be deployed to your local .m2 directory and the generator build will work.
git clone -b odf-reference https://github.com/tdf/odftoolkit
There you may test quickly the output for one RNG expression via a test (no regression testing yet)!
Before I explain the solution, just a quick description of RNG and MSV in a nutshell.
RelaxNG in a Nutshell - compared to XSD
The RNG specification is about 21 pages (DINA4) long and easy to read.
The XSD specification is about 380 pages and I find only the Primer readable.
The W3C Schema Grammar 1.0 2nd Ed. (28 October 2004) - 364 DIN A4 pages:
The W3C Schema Grammar 1.1 (5 April 2012) - 387 DIN A4 pages:
In addition, there is a paper that states RNG is the more expressive languages over XSD and DTD. Others state similar.
Note: There is a RNG Tutorial (22 pages) and I have merged the errata into the RNG spec (still a PullRequest).
What I yet not fully understand on RNG is the advantage of simplification the RNG into a normalized run-time model becoming a binary tree.
The RNG specific describes like a choice
<choice> p1 p2 p3 </choice>
is transformed into binary-tree run-time representation:
<choice> <choice> p1 p2 </choice> p3 </choice>
MSV in a Nutshell
MSV is a Multi-Schema validator as it reads various Grammars into a single ueber model, the Abstract grammar model (AGM), which is based on RNG expressions all stored in a HashMap the ExpressionPool.
Similar to the Java Object superclass there is the Expression class where all Expressions the atoms of a grammar file are made of.
All possible expression types are listed in an expression visitor.
I personally find visitors not such intuitive, so in a sentence explained:
"Expression.java" - the base class of all expressions defines an abstract method for each visitor type (type differ on return type), like the visitor returning void is called ExpressionVisitorVoid.java.
The bad side: I find it unintutive, the good side: all functionality is written in the visitor.
The Solution in more Detail
I am using this visitor pattern to start with an expression and traverse its descendants. The functionality is triggered from the XMLModel class so its grammar is parsed once (and cached) to find the "heads of islands" parts of the grammar graph which is multiple used and might lead into infinite loops during traversal.
This functionality is in the end called from the Velocity HTML template for OdfReference.html.
What's missing - IMHO
(e.g. indent for each node child level, perhaps CSS colors for aligned brackets?