aerhard / linter-autocomplete-jing

Jing-based autocomplete and validation of XML documents in Atom
https://atom.io/packages/linter-autocomplete-jing
MIT License
19 stars 3 forks source link

Help configuring catalog in rules #40

Closed agusmba closed 7 years ago

agusmba commented 7 years ago

Hi Alexander!

First of all, thank you for creating such a useful plugin! I'm always on the lookout for tools that allow me to properly validate xml messages, without requiring me to fire up XMLSpy.

That said, I've bee able to configure my atom config.cson in order to add a rule for a specific schema like this:

    rules: [
      {
        priority: 1
        test:
          rootNs: "urn:namespace1:7:0"
        outcome:
          schemaProps: [
            {
              lang: "xsd"
              path: "D:\\borrar\\xsd\\namespace1_v7_0.xsd"
            }
          ]
      }
    ]

This works like a charm!

However, I'd like to be able to validate against many different schemas. Instead of entering each schema in the config, I wanted to have a more portable solution to my namespace-schema mappings. I thought using a catalog would do the trick. But when I try to use a catalog in the rules like this:

      {
        priority: 1
        test:
          rootNs: "urn:namespace2:7:1"
        outcome:
          xmlCatalog: "D:\\borrar\\xsd\\xbid-catalog.xml"
      }

The content of the catalog:

<?xml version="1.0"?>
  <catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">

    <system systemId="urn:namespace1:7:0"
            uri="namespace1_v7_0.xsd"/>

    <system systemId="urn:namespace2:7:1"
            uri="namespace2_v7_1.xsd"/>

  </catalog>

When I load an xml file with a namespace in the catalog I get an error

[linter-autocomplete-jing] Cannot convert undefined or null to object
TypeError: Cannot convert undefined or null to object
    at Function.from (native)
    at toConsumableArray (file:///d:/Usuarios/marbarag/.atom/packages/linter-autocomplete-jing/lib/main.coffee:1:1)
    at file:///d:/Usuarios/marbarag/.atom/packages/linter-autocomplete-jing/lib/main.coffee:1:1
    at getSchemaProps (file:///d:/Usuarios/marbarag/.atom/packages/linter-autocomplete-jing/lib/main.coffee:1:1)
    at Object.lint (file:///d:/Usuarios/marbarag/.atom/packages/linter-autocomplete-jing/lib/main.coffee:1:1)
    at promises.push.Promise.then._this.emitter.emit.linter (file:///d:/Usuarios/marbarag/.atom/packages/linter/lib/linter-registry.js:63:26)
    at file:///d:/Usuarios/marbarag/.atom/packages/linter/lib/linter-registry.js:62:23
    at Set.forEach (native)
    at LinterRegistry.lint (file:///d:/Usuarios/marbarag/.atom/packages/linter/lib/linter-registry.js:60:18)
    at file:///d:/Usuarios/marbarag/.atom/packages/linter/lib/linter.coffee:98:16
    at Function.module.exports.Emitter.simpleDispatch (D:\Usuarios\marbarag\AppData\Local\atom\app-1.12.6\resources\app.asar\node_modules\event-kit\lib\emitter.js:25:14)
    at Emitter.module.exports.Emitter.emit (D:\Usuarios\marbarag\AppData\Local\atom\app-1.12.6\resources\app.asar\node_modules\event-kit\lib\emitter.js:129:28)
    at file:///d:/Usuarios/marbarag/.atom/packages/linter/lib/editor-linter.js:86:22
    at file:///d:/Usuarios/marbarag/.atom/packages/linter/lib/helpers.coffee:25:18

Maybe I'm trying to use catalogs for something they're not for (I don't want to add any explicit schemaLocation references to my xml files).

Do you have any recommendation on how to configure many namespace-schema mappings outside of atom's config and still use your plugin?

Thank you!!!

aerhard commented 7 years ago

Hi -- thank you for your message! The package currently expects schemaProps to be present. I think this is an unnecessary constraint -- I'll change the code so it will work without that property. If you've only got a single catalog file you could also refer to it in the top-level xmlCatalog property, i.e. without specifying a rule. But I'm not sure if using catalogs can give you what you're looking for: The catalog resolver only maps schema locations provided in schema references (for example, in an xml-model processing instruction or in xsi:schemaLocation) but it doesn't know about details of instance documents, so in order to make use of a catalog file you need to provide schema references in your instance documents. You can avoid this by specifying rules like in your first example. The rules don't have to be in Atom's config file, you can also store them at a different location and register them with apm link (see https://github.com/aerhard/xml-demo-package for an example) -- would that help?

agusmba commented 7 years ago

Yes, you are right. The catalog will not help me in this particular case.

Thanks for the pointer to the demo!

I will try to set it up.

Can I ditch the grammars directory altogether since I want to add schemas to the general xml grammar?

aerhard commented 7 years ago

glad I could help! yes -- you can omit the directory. You should only need the content of the settings directory (the file names are not relevant, you can even have multiple files there) and package.json (plus the schemata if you want to include them)

agusmba commented 7 years ago

Ok, thanks a lot!

I already cloned the demo and modified it to add a first sample schema like this in the my-config.cson:

'.text.xml':
  'validation':
    'rules': [
      {
        priority: 1
        test:
          rootNS: "urn:namespace1:7:1"
        outcome:
          schemaProps: [
            {
              lang: "xsd"
              path: "../schemata/namespace1_v7_1.xsd"
            }
          ]
      }
    ]

I did the apm link, and I see my package under atom's packages

But it doesn't seem to work (I don't get validation on that schema). I changed the first line, removing the "dmox" part, but maybe it's still not correct? (EDIT: Ok, actually I didn't edit the first line, it's like this in the demo also ;-))

Thanks!!

aerhard commented 7 years ago

mhm. the file you've posted looks good on first sight. Does restarting Atom (Ctrl-Alt-R) help? If not: Did you change the package name in package.json? If the demo package is also registered in Atom and both have the same name that might cause issues.

agusmba commented 7 years ago

Hi!

Restarting did not help.

I did change the name in the package.json, but the new name is different from the name of the cson file in the settings directory. Do they need to match?

If I open the developer tools in Atom, and write:

> atom.config

I do not see the new plugin configuration anywhere (even though the plugin-view shows it as active), nor do I see the linter-autocomplete-jing configuration modified with the new rules.

Sorry to be bothering you like this (I'm not used to tinkering with atom plugins), and thanks for all the help!

aerhard commented 7 years ago

no worries! probably found the error -- rootNs needs to be camel case

agusmba commented 7 years ago

Oooops. Indeed! Well, that was embarrassing.

It now works perfectly!

Thank you!!!