Page 1 of 1

Logical Model View -- save as Relax NG

Posted: Tue Dec 02, 2008 11:01 pm
by madde001
Hi Sorin et al,

I'm creating a big set of RelaxNG schemas that are composed out of a lot of modules using many <include> and <externalRef> elements.

I love being able to see the "post-simplification" version of the schema as the Logical Model View (LMV) diagramming pane. Currently you can save the LMV as a diagram image, and that's great.

But I have discovered two use cases for also being able to save the "post-simplification" schema as parsable Relax NG.

(1) Trang's RelaxNG-to-XMLSchema conversion does not support <externalRef>. Therefore, if I have a schema developed in RelaxNG that uses <externalRef>, and I want to Trang-convert it into XMLSchema, I need to manually go in and replace all the <externalRef> with the code fragments they reference. It seems like (and maybe I'm wrong here) if only I could get hold of the post-simplification version of my RelaxNG schema (which has all the <externalRef> resolved), I could get around doing this manually.

(2) My modular project design is intended to generate many different variations of my end-schema (kind of like an Abstract Factory pattern). Because the various customized end-schemas depend on a lot of <include> and <externalRef>, I will have to distribute to end users a package with many individual files to support the end-schemas.

Some users, though, might only be interested in one specific end-schema. They like to have the whole thing as a single, neat RNG file with no external dependencies on other files. It seems like (and again, maybe I'm wrong here) that the post-simplification version of the schema would be just the ticket.

So anyway, what do you think?

John

Re: Logical Model View -- save as Relax NG

Posted: Thu Dec 04, 2008 3:38 pm
by george
Hi John,

You can find below a simple class that gives you the RelaxNG schema in a single file. You need onvdl.jar or the latest Jing (jing-20081028, as the previous version of Jing contained a bug in the PatternDumper that I fixed both in oNVDL and in the latest Jing) in the classpath to run.

Code: Select all


import java.io.File;

import org.relaxng.datatype.helpers.DatatypeLibraryLoader;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;

import com.thaiopensource.relaxng.impl.PatternDumper;
import com.thaiopensource.relaxng.impl.SchemaBuilderImpl;
import com.thaiopensource.relaxng.impl.SchemaPatternBuilder;
import com.thaiopensource.relaxng.parse.sax.SAXParseable;
import com.thaiopensource.util.UriOrFile;
import com.thaiopensource.xml.sax.ErrorHandlerImpl;
import com.thaiopensource.xml.sax.Jaxp11XMLReaderCreator;

/**
* @author George Bina
*/
public class GetResolvedRelaxNGSchema {

public static void main(String[] args) {
if (args.length == 0)
System.out.println("Pass the RelaxNG schema as command line parameter!");
else {
try {
ErrorHandler eh = new ErrorHandlerImpl();
PatternDumper.dump(System.out, SchemaBuilderImpl.parse(
new SAXParseable(new Jaxp11XMLReaderCreator(), new InputSource(
UriOrFile.fileToUri(new File(args[0]))), eh), eh,
new DatatypeLibraryLoader(), new SchemaPatternBuilder(), false));
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
This can be easily integrated also in oXygen as external tool and you can use the ${cf} editor variable to point to your currently edited file.

Regards,
George

Re: Logical Model View -- save as Relax NG

Posted: Thu Dec 04, 2008 5:34 pm
by madde001
George,

This is great! But I'm afraid you overestimate my Java abilities :oops: -- can you possibly send this to me pre-packaged up as a .jar?

Thanks, John

Re: Logical Model View -- save as Relax NG

Posted: Fri Dec 05, 2008 6:56 pm
by george
Hi John,

I packed up the class plus onvdl.jar plus two RNG schemas as a sample at
http://www.oxygenxml.com/update/resolveRNG.zip

You need to invoke from the folder where you have the files as

Code: Select all

java -cp .;onvdl.jar GetResolvedRelaxNGSchema x.rng
For example:

Code: Select all


D:\users\george\workspace\test\resolveRNG>type x.rng
<?xml version="1.0" encoding="UTF-8"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0">
<start>
<element name="x">
<externalRef href="y.rng"/>
</element>
</start>
</grammar>

D:\users\george\workspace\test\resolveRNG>type y.rng
<?xml version="1.0" encoding="UTF-8"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0">
<start>
<element name="y">
<text/>
</element>
</start>
</grammar>

D:\users\george\workspace\test\resolveRNG>java -cp .;onvdl.jar GetResolvedRelaxNGSchema x.rng
<?xml version="1.0"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0">
<start>
<element>
<name ns="">x</name>
<ref name="p0"/>
</element>
</start>
<define name="p0">
<element>
<name ns="">y</name>
<ref name="p1"/>
</element>
</define>
<define name="p1">
<text/>
</define>
</grammar>
Best Regards,
George

Re: Logical Model View -- save as Relax NG

Posted: Fri Dec 05, 2008 6:59 pm
by madde001
George, You're the best. I'll get back to you with feedback.
Best, John

Re: Logical Model View -- save as Relax NG

Posted: Sat Dec 06, 2008 6:45 am
by madde001
George,

It works! I installed as an external tool, as you suggested. And the result (from a schema with dozens of externalRefs and includes) works fine as an input to Trang, making me a happy man.

It's interesting that one or two stylistic conventions in the xml are different from the way the LMV diagram presents it (e.g. LMV diagram preserves <element name="xyz"/> whereas xml version simplifies all to <element><name>xyz</name></element>). Are there some "de-simplifications" in the LMV diagram?

Thanks again! I'd vote to see "generate simplified rng" as a built-in menu command in some future release of oxygen.

John

Re: Logical Model View -- save as Relax NG

Posted: Sat Dec 06, 2008 10:04 am
by george
Hi John,

We preferred a little more compact and readable representation for the logical model diagram so instead of passing the pattern through the PatternDumper visitor we have a different visitor that, as you noted, puts the name as attribute if there is just one name (not a more complex name class) and generates more meaningful pattern names (like elementName.content) than p0 ,p1, etc.
I recorded an issue on our Jira with the support for putting this action directly in oXygen. Actually we have a "Flatten schema" action that currently works for XML Schema (given an XML Schema containing includes outputs a single schema file with the includes replaced with the included content) and we can provide the same action for Relax NG to get the simplified schema.

Best Regards,
George

Re: Logical Model View -- save as Relax NG

Posted: Sat Dec 06, 2008 4:10 pm
by madde001
For most purposes, I like your more compact and human-readable style. Maybe you could offer both yours and the official, fully simplified form.

John

Re: Logical Model View -- save as Relax NG

Posted: Tue Aug 18, 2009 6:52 pm
by shudson310
would it be possible to re-post the jar file? I have a similar need to flatten the DocBook Publishers schema to help with review of the specification.

When I try to follow the link, it is currently broken.

Thanks and best regards,

--Scott

Re: Logical Model View -- save as Relax NG

Posted: Tue Aug 18, 2009 8:24 pm
by george
Hi Scott,

You are lucky ;). I just uploaded a few hours ago a new build of Jing at
http://code.google.com/p/jing-trang/downloads/list
http://jing-trang.googlecode.com/files/ ... 090818.zip

You can use that to get a simplified schema using something like

java -jar jing.jar -s yourSchema.rng

The code posted previously in this topic did the same thing for older version of Jing.

Best Regards,
George

Re: Logical Model View -- save as Relax NG

Posted: Tue Aug 18, 2009 9:05 pm
by shudson310
Thanks, George! Nice timing! I tried it out, and it appears to work very well!

Best regards,

--Scott

Re: Logical Model View -- save as Relax NG

Posted: Wed Mar 23, 2011 1:15 am
by tara_athan
Is it possible now to flatten Relax NG from within Oxygen? The earlier Java jar could be added as an external tool, but now that the capability is there in Jing, what is the best way to approach this?

Re: Logical Model View -- save as Relax NG

Posted: Wed Mar 23, 2011 1:27 pm
by george
No, it was not yet implemented - the above solution to configure an external tool is still the current option. Note that you can use an editor variable to refer to the current file and thus the external tool will work automatically for any schema you have open in oXygen.

Best Regards,
George

Re: Logical Model View -- save as Relax NG

Posted: Wed Mar 23, 2011 8:14 pm
by tara_athan
I am having trouble understanding how to configure this. I first checked that the following command line input works correctly:
java -jar "C:\MyPath\OxygenXMLEditor\external_tools\jing-20090818\bin\jing.jar" -cs dishornlog_standard.rnc > dishornlog_standard_flatten.rng

Then I created a new external tool....
For the working directory I put the code for the current directory
${cfd}

For command line I put
java -jar "C:\MyPath\OxygenXMLEditor\external_tools\jing-20090818\bin\jing.jar" -cs ${cfne} > ${cfn}_flatten.rng

The tool runs and puts the output in the console, then looks for the file ">" and ends with an error message.

How do I redirect the output from the console to a file?

I am on Windows XP.

Re: Logical Model View -- save as Relax NG

Posted: Wed Mar 23, 2011 11:49 pm
by george
You need to run the shell (I think that is cmd on Windows), that is the application that handles the output redirection to a file. I am on a Mac and I cannot give you the exact details but if you have problems further one of my colleagues on Windows will surely help you.

Regards,
George

Re: Logical Model View -- save as Relax NG

Posted: Thu Mar 24, 2011 4:04 pm
by adrian
Hello,

Like George said, you can use cmd:
cmd /C java -jar "C:\MyPath\OxygenXMLEditor\external_tools\jing-20090818\bin\jing.jar" -cs ${cfne} > ${cfn}_flatten.rng

Make sure the working directory is correct or use the current file directory editor variable: ${cfd}

Regards,
Adrian

Re: Logical Model View -- save as Relax NG

Posted: Sat Mar 26, 2011 1:05 am
by tara_athan
Thanks, I got this working. For the benefit of other command-line challenged folks out there, this is the way the command line field should look

cmd.exe /c java -jar "C:\MyPath\jing-20091111\bin\jing.jar" -s ${cfne} > ${cfne}_flatten.rng

OR, for schema in compact syntax

cmd.exe /c java -jar "C:\MyPath\jing-20091111\bin\jing.jar" -sc ${cfne} > ${cfne}_flatten.rng

Re: Logical Model View -- save as Relax NG

Posted: Sun Mar 27, 2011 1:14 am
by tara_athan
One more twist on this: can I configure the external tool to add this file to the current project?

Re: Logical Model View -- save as Relax NG

Posted: Mon Mar 28, 2011 3:16 pm
by adrian
I'm afraid you can't configure the external tool to add the output file to the project.

An alternative is to manually add the parent directory(or another ancestor) of the output file to the project. In the project tree right click on a logical resource or the tree root and from the contextual menu choose Add Folder.

After generating the file, refresh the parent directory and the file will appear in the tree.

Regards,
Adrian