Support RelaxNG validation.
Support RelaxNG validation.
It would be an immense help to have this. Is there anything preventing it from being merged?
@adunning thanks for your feedback.
At first please wote at https://github.com/redhat-developer/vscode-xml/issues/450
The main problem is that RelaxNG is not our priority and it requires a lot of work (to support validation with error range and completion,hover, definition based on relaxng). Our current goal is to support robust support for XML, XSD and DTD.But if we see that we have more and more people(liek you) who are interested we could work.
This PR is based on Jing, but I know @svanteschubert wanted to provide a relaxng support based on MSV. See https://github.com/redhat-developer/vscode-xml/issues/451#issuecomment-858080135
@svanteschubert what is the status of your work?
We will need to do a bit of work in order to get the binary to work
For org.relaxng:jing, I couldn't find any recent entry on ClearlyDefined. https://clearlydefined.io/definitions/maven/mavencentral/org.relaxng/jing/20181222 doesn't have the necessary score.
$ mvn clean verify -DskipTests -Pverify-iplog
...
...
$ cat target/dash/summary | grep -v approved
maven/mavencentral/isorelax/isorelax/20030108, , restricted, clearlydefined
maven/mavencentral/org.relaxng/jing/20220510, , restricted, clearlydefined
So these libraries would need to be approved via. https://gitlab.eclipse.org/eclipsefdn/emo-team/iplab . You can use Create a request to vet Third-party content in order to do it manually. There's also an automated process that requires you to create at GitLab api token.
See https://gitlab.eclipse.org/eclipsefdn/emo-team/iplab/-/issues/3540, https://gitlab.eclipse.org/eclipsefdn/emo-team/iplab/-/issues/3539
Here's what's needed to get the binary working:
diff --git a/org.eclipse.lemminx/src/main/resources/META-INF/native-image/resource-config.json b/org.eclipse.lemminx/src/main/resources/META-INF/native-image/resource-config.json
index 12a4fcdb..18d3640d 100644
--- a/org.eclipse.lemminx/src/main/resources/META-INF/native-image/resource-config.json
+++ b/org.eclipse.lemminx/src/main/resources/META-INF/native-image/resource-config.json
@@ -50,6 +50,12 @@
{
"name": "org.apache.xerces.impl.msg.XMLMessages"
},
+ {
+ "name": "com.thaiopensource.datatype.xsd.resources.Messages"
+ },
+ {
+ "name": "com.thaiopensource.relaxng.pattern.resources.Messages"
+ },
{
"name": "org.eclipse.lemminx.extensions.xerces.xmlmodel.msg.XMLMessages"
},
Here's what's needed to get the binary working:
Thanksso much for your feedback. I'm surprised that there is just this fix to do. I think completion doesn't work with binary because I'm using Java reflection (for the moment).
I'll double check, but I thought it was working when I tried it.
edit: yep, it seems to be working with the binary
Ok this PR should work correctly now. All features are tested with some Junit tests and the integration of RelaxNG should be clean (we use system cache, commons error range are managed, etc).
The only thing that I need to implement is the documentation, but for the moment I need to do some investigation.
You can take for instance this XML:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"?>
<TEI xmlns="http://www.tei-c.org/ns/1.0">
</TEI>
and play with validation and completion.
Here a demo:

It should work too with compact syntax.
Type Definition to open the grammar element/attribute from XML should work now:

I clean my PR and I support documentation (but not for compact syntax)
- for completion:

- for hover:

Given:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="asdf.rnc"?>
<addressBook>
<card>
<name>David</name>
<email></email>
</card>
</addressBook>
and an empty asdf.rnc, the "schema invalid" error is placed on the first line of the file (it's not adjusted properly), and 2 NPE appear in the console.
If you reference an empty .rng file, then the error message that appears is ::::-1:-1:-1:Premature end of file.xml(RelaxNGNotFound). It would be nice if we could remove the ::::-1:-1:-1: part
It would be nice to associate all .rng files with the relaxng.rng or relaxng.xsd schema. Do you want to do this in a future PR?
and an empty asdf.rnc, the "schema invalid" error is placed on the first line of the file (it's not adjusted properly), and 2 NPE appear in the console.
If you reference an empty .rng file, then the error message that appears is ::::-1:-1:-1:Premature end of file.xml(RelaxNGNotFound). It would be nice if we could remove the ::::-1:-1:-1: part
It should be fixed now and you should see the error as referenced diagnostic because the error comes from the schema and not from the XML:

It would be nice to associate all .rng files with the relaxng.rng or relaxng.xsd schema. Do you want to do this in a future PR?
done, now you should have validation and completion for relaxng grammar:

Don't say "This class is a copy paste of", say "This class is a copy of "
Don't say "This class is a copy paste of", say "This class is a copy of "
fixed
I add 2 snippets support for RelaxNG:
- one to create an XML file bound with RelaxNG
- one to create a RelaxNG *.rng grammar file
Here a demo which show how it is easy to create an XML bound with a RelaxNG grammar created by snippets:

If you reference an empty .rng file, the SAXParseException appears in the logs.
If you reference an empty .rng file, the SAXParseException appears in the logs.
It should be fixed.