IntelliJ Idea: Schemas and DTDs / configuring XML catalog

3.6k views Asked by At

I have a lot of xml files in my project which are described with many xsd schema files. XSD schemas use complex namespace structure and I want to configure IDE (IntelliJ Idea) to resolve URIs of these schemas on my local file system (https://www.jetbrains.com/idea/help/xml-catalog.html). So I open Idea Settings, select Language & Frameworks -> Schemas and DTDs -> XML Catalog and point the path to xml-catalog.properties file with following content:

catalogs=xml-catalog.xml
relative-catalogs=yes
#verbosity=99

Next I create xml-catalog.xml file (in the same directory as the xml-catalog.properties file):

<?xml version="1.0"?>
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="urn:oasis:names:tc:entity:xmlns:xml:catalog http://www.oasis-open.org/committees/entity/release/1.0/catalog.xsd"
         prefer="public">
    <rewriteSystem systemIdStartString="http://www.mycompany.com/schemas" rewritePrefix="file:///c:/Projects/MyProject/schemas"/>
</catalog>

I expect Idea will resolve all the schemas with prefix http://www.mycompany.com/schemas in my local directory c:/Projects/MyProject/schemas and uses them for validating and code highlighting. But all the URIs in the editor remain red... Googling and playing with paths, URIs and directives in xml-catalog.xml gave no results for me...

Could anyone show me working XML catalog settings which help to resolve at least one URI or public/system or point me detailed manual of doing this?..

1

There are 1 answers

1
Nicolas Rouquette On BEST ANSWER

Per the OASIS XML Catalog specification [1] your example should work as follows:

http://www.mycompany.com/schemas/foo.xsd

rewrites to:

file:///c:/Projects/MyProject/schemas/foo.xsd

Have you tried using a 'rewriteURI' [2] instead of a 'rewriteSystem' [1] ?

Here is an example that we've been using extensively for several years at JPL. At least, I know this works reliably on linux & macosx; however, I don't make any claims about windows.

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

    <rewriteURI 
      rewritePrefix="file:./www.omg.org/" 
      uriStartString="http://www.omg.org/"/>

</catalog>

With the Apache XML Resolver 1.2 library implementation [3], the above rewrites the following URI:

http://www.omg.org/spec/UML/20110701/UML.xmi

to:

file:./www.omg.org/spec/UML/20110701/UML.xmi

However, IntelliJ 14.1.3 says that the above is ill-formed; specifically, IntelliJ claims the attribute 'uriStartString' is not allowed and that 'rewriteURI' is missing the 'uriIdStartString' Attribute. That is, IntelliJ expects this:

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

    <rewriteURI 
      rewritePrefix="file:./www.omg.org/" 
      uriIdStartString="http://www.omg.org/"/>

</catalog>

The Apache XML Resolver 1.2 library does not handle this form.

Who to trust: IntelliJ? OASIS? Apache XML Resolver?

It does not help that the OASIS XML Catalog spec 1.0 uses 'uriStartString' in [2] and Appendix B (non-normative) but 'uriIdStartString' in Appendix A (non-normative).

It would be great if Norm Welch could comment on this; after all he wrote the OASIS XML Catalog spec and has been involved in the Apache XML Resolver implementation.

[1] https://www.oasis-open.org/committees/entity/spec-2001-08-06.html#s.rewritesystem

[2] https://xerces.apache.org/xml-commons/components/resolver/resolver-article.html

[3] https://www.oasis-open.org/committees/entity/spec-2001-08-06.html#element-rewriteURI