redhat-developer / vscode-xml

Editing XML in Visual Studio Code made easy
Eclipse Public License 2.0
256 stars 79 forks source link

Schema Declaration in Processing Instructions and RELAXNG/ODD Schema #236

Closed BalduinLandolt closed 4 years ago

BalduinLandolt commented 4 years ago

First of all, thanks for this great extension!

I'm unsure if it's just me being dumb... But the only way I can get schema validation to work is to use xml.fileAssociations in the settings. But that's somewhat impractical, as I can only add one schema and then every XML is validated with that one schema.
I'd love to be able to validate XMLs simply by adding the processing instruction <?xml-model href="some-schema.xsd" type="application/xml" schematypens="http://www.w3.org/2001/XMLSchema"?> (with the schema being a local file relative to the XML file's location, or a URL of a .xsd somewhere in the internet).
Maybe I'm all wrong... but I would have actually expected this to be a fairly straight forward functionality.

And also, having RELAXNG or even ODD schema validation on top of .dtd and .xsd would be amazing.

angelozerr commented 4 years ago

But the only way I can get schema validation to work is to use xml.fileAssociations in the settings. But that's somewhat impractical, as I can only add one schema and then every XML is validated with that one schema.

XML Schema support should work, if you have some trouble, please attach a zip which contains your vscode project with XML and XML Schema and explain us what you want to do.

And also, having RELAXNG or even ODD schema validation on top of .dtd and .xsd would be amazing.

For RelaXNG, it exists an issue at https://github.com/eclipse/lemminx/issues/237 but I fear it's a long and hard task. I wonder if RelaxNG is a lot used compare to XML Schema?

BalduinLandolt commented 4 years ago

Thanks for the quick reply!

XML Schema support should work, if you have some trouble, please attach a zip which contains your vscode project with XML and XML Schema and explain us what you want to do.

Alright. I thought it might just be my mistake.
I'll have another look if I get it to work. And if not, I'll gladly upload my files.

For RelaXNG, it exists an issue at eclipse/lemminx#237 but I fear it's a long and hard task. I wonder if RelaxNG is a lot used compare to XML Schema?

Well... I suppose on a global scale, RelaXNG is not used a lot. By no means as much as XML Schema, at least. But it definitely gets used: For example, the entire Text Encoding Initiative and all TEI customizations are built around ODD, RelaXNG and Schematron Schemas and usually use RelaXNG. So that's countles projects working with .rng Schemas, and especially big institutions like the German Text Archive or the Cambridge Digital Library providing all of their data in XML that is validated against .rng Schemas.
So basically, everyone in the humanities who wants to work with digital text, will either not have his XMLs validated, or pay for Oxygen XML editor ($99 upwards)

Long story short: I'm sure there are more people who wold be very greatful to see this implemented. :-)

BalduinLandolt commented 4 years ago

XML Schema support should work, if you have some trouble, please attach a zip which contains your vscode project with XML and XML Schema and explain us what you want to do.

I did try it out, see the attached zip file: validation_test.zip

When I open these files in Oxygen XML editor, I get the expected behaviour: file_invalid.xml does not validate, file_valid.xml does.
When I open the files in VS Code, nothing happens, but a hint "No grammar constraints (DTD or XML Schema)."
When I add

    "xml.fileAssociations": [
        {
            "systemId": "C:\\Users\\baldu\\OneDrive\\Desktop\\validation_test\\schema.xsd",
            "pattern": "**/*.xml"
        }
    ],

it works perfectly again... I'm really confused what I'm doing wrong.

angelozerr commented 4 years ago

It seems that you are using xml-model https://www.w3.org/TR/xml-model/#the-xml-model-processing-instruction which is not supported (why I don't know if Xerces can support it, let me investigate that).

But the standard mean to bind your XML with a XML Schema is:

<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="./schema.xsd">

I mean, if your write your XML like:

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="./schema.xsd">
    <a>
        blah
    </a>
    <a>
        <b/>
    </a>
</root>

It should work.

BalduinLandolt commented 4 years ago

Cool, that works indeed. Thanks!

Again, in the context of TEI, I've seen xml-model used a lot. So if that would be supported eventually, that would be great!

BalduinLandolt commented 4 years ago

@angelozerr where would I start best, if I wanted to contribute either to the support of the xml-model processing instruction or the implementation of relaxng in the lemminx language server?

angelozerr commented 4 years ago

@angelozerr where would I start best, if I wanted to contribute either to the support of the xml-model processing instruction or the implementation of relaxng in the lemminx language server?

Indeed, it's the LemMinx LS which should manage that which is written in Java. It should be fantastic to have those contribution, I think we should manage at first xml-model processing instruction (how to manage that with Xerces) and RelaXNG (quick search with RelaxNG wriiten in Jav ais https://github.com/relaxng/jing-trang)

I suggets you that you create several little issues in LemMinx (what you want to have/provide)

BalduinLandolt commented 4 years ago

Indeed, it's the LemMinx LS which should manage that which is written in Java. It should be fantastic to have those contribution, I think we should manage at first xml-model processing instruction (how to manage that with Xerces) and RelaXNG (quick search with RelaxNG wriiten in Jav ais https://github.com/relaxng/jing-trang)

Let's not get ahead of ourselfs... This is somewhat beyond the scope of my usual projects. But I see what I can do. ;-)

I suggets you that you create several little issues in LemMinx (what you want to have/provide)

Aye, will do.
But since the whole language server thing is new to me, I will need some help here and there, I suspect...

angelozerr commented 4 years ago

Aye, will do. But since the whole language server thing is new to me, I will need some help here and there, I suspect...

@BalduinLandolt I read some documentation about RelaxNG and starts playing with Jing. I see more what it is RelaxNG and what we need to do to support it and to be honnest with you it can be a long task if we want to support RelaxNG like we have done for XML Schema (DTD is not finished yet), I mean:

As you can see, there are a lot of big tasks and it is not detailed. I think the first step is to manage xml-model processing instruction. I need to investigate if Jing can manage that?

I'm afraid that it's a very long and hard task. We love contribution, and we try to do our best to help contributors, I suggets you that you read https://github.com/redhat-developer/vscode-xml#contributing

But as I tried to explain you, it's a very big task, so the first step is to play with Jing and xml-model before trying to integrate to LemMinx.

angelozerr commented 4 years ago

@BalduinLandolt I think your original requirement is https://github.com/eclipse/lemminx/issues/633

For RelaxNG, let's create another issues.

BalduinLandolt commented 4 years ago

Yes, let's keep the processing instructions and the RelaxNG/Schematron separate issues.

I'll see what I can do. But I'm rather busy with other things, so don't expect too frequent stuff from me. (I'm mostly doing this to procrastinate from other things... ^^)

angelozerr commented 4 years ago

I'll see what I can do. But I'm rather busy with other things, so don't expect too frequent stuff from me. (I'm mostly doing this to procrastinate from other things... ^^)

I will study this issue once I will fix some bugs with DTD

angelozerr commented 4 years ago

Fixed with https://github.com/eclipse/lemminx/issues/633