eerohele / exalt

A Sublime Text plugin for validating and formatting XML documents
MIT License
22 stars 3 forks source link

Ignore multiple schemaLocation #19

Closed DavorPadovan closed 5 years ago

DavorPadovan commented 5 years ago

XML I'm trying to validate has multiple schemaLocation entries: xsi:schemaLocation="http://example.com/schemas/validation-rules.xsd validation-rules.xsd"

I also have catalog.xml set up to rewrite public schemas to local FS: <rewriteURI uriStartString="http://example.com/schemas/" rewritePrefix="file:///C:/SW/schemas/" />

But this doesn't work as expected. It works only if I remove second part (validation-rules.xsd) from schemaLocation value. Is there any way to ignore this part?

eerohele commented 5 years ago

I don't think Exalt correctly accounts for that scenario at the moment because I didn't know you can refer to more than one schema location. I'll look into it.

eerohele commented 5 years ago

Actually, I remembered wrong: it looks like Exalt always uses the last entry in the schemaLocation or noNamespaceSchemaLocation attribute.

I don't know that that's the smartest way for Exalt to work, but it means that you could try adding something like this into your XML catalog:

<system systemId="validation-rules.xsd" uri="file:///C:/SW/schemas/validation-rules.xsd"/>

Remember to restart Sublime Text after making that change for the changes to take effect.

Please let me know whether that solves the issue for you.

eerohele commented 5 years ago

In fact (refreshing my memory here, been a while since I've needed to work with this stuff…), it seems that xsi:schemaLocation="http://example.com/schemas/validation-rules.xsd validation-rules.xsd" is basically a hint that says:

The XML schema for XML nodes in the http://example.com/schemas/validation-rules.xsd namespace is located at validation-rules.xsd.

So in that sense, the current behavior seems more or less correct and adding a <system> entry like the one I described above is probably your best bet.

DavorPadovan commented 5 years ago

The solution you described above is working. But the problem is that we have a lot of different XSD schemas with the same name - we distinguish them by domain name, not by filename.

eerohele commented 5 years ago

I see. I'll need to look into how to best solve that issue.

eerohele commented 5 years ago

Exalt's implementation of schemaLocation is somewhat naïve and probably incorrect, but I'm having trouble finding definitive information on how it should work. I honestly don't have the time (or the inclination) to try to glean the information from the W3C specification, either.

A simple way to fix this would be to use the namespace (the bit preceding the space in the xsi:schemaLocation attribute) instead of the URI hint (the bit following the space).

However, that might break backwards compatibility for some users, which I don't want to do.

I'll try to see if I can modify the code to account for both options.

eerohele commented 5 years ago

This should be fixed in v0.3.7.

I think you'll need to add something like this in your XML catalog:

<system systemId="http://example.com/schemas/validation-rules.xsd" uri="file:///C:/SW/schemas/validation-rules.xsd"/>

It'll take a while for the new version to land in Package Control, but once it does, could you give it a go and let me know whether it fixes the issue for you?

DavorPadovan commented 5 years ago

Thank you! I will try this approach.

DavorPadovan commented 5 years ago

It works! Even without changing my catalog.xml file. Thank you again!

eerohele commented 5 years ago

Glad to hear it!