简体   繁体   English

IntelliJ Idea:模式和DTD /配置XML目录

[英]IntelliJ Idea: Schemas and DTDs / configuring XML catalog

I have a lot of xml files in my project which are described with many xsd schema files. 我的项目中有很多xml文件,其中包含许多xsd模式文件。 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 ). XSD架构使用复杂的名称空间结构,我想配置IDE(IntelliJ Idea)来解析本地文件系统( https://www.jetbrains.com/idea/help/xml-catalog.html )上这些架构的URI。 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: 因此,我打开“想法设置”,选择“语言和框架”->“架构和DTD”->“ XML目录”,然后将路径xml-catalog.properties具有以下内容的xml-catalog.properties文件:

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-catalog.xml文件(与xml-catalog.properties文件位于同一目录中):

<?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. 我希望Idea将解析本地目录c:/Projects/MyProject/schemas所有带有前缀http://www.mycompany.com/schemas c:/Projects/MyProject/schemas ,并将其用于验证和代码突出显示。 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... 但是编辑器中的所有URI仍然是红色的。谷歌搜索和玩xml-catalog.xml路径,URI和指令对我没有任何结果...

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?.. 任何人都可以向我展示可以帮助解析至少一个URI或公共/系统的XML目录设置的工作方法,或者为我提供执行此操作的详细手册?

Per the OASIS XML Catalog specification [1] your example should work as follows: 根据OASIS XML目录规范[1],您的示例应如下工作:

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

rewrites to: 重写为:

file:///c:/Projects/MyProject/schemas/foo.xsd 文件:/// C:/Projects/MyProject/schemas/foo.xsd

Have you tried using a 'rewriteURI' [2] instead of a 'rewriteSystem' [1] ? 您是否尝试过使用'rewriteURI'[2]而不是'rewriteSystem'[1]?

Here is an example that we've been using extensively for several years at JPL. 这是我们在JPL上已经广泛使用了几年的示例。 At least, I know this works reliably on linux & macosx; 至少,我知道这可以在linux&macosx上可靠地工作。 however, I don't make any claims about windows. 但是,我对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: 通过Apache XML Resolver 1.2库实现[3],以上代码重写了以下URI:

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

to: 至:

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

However, IntelliJ 14.1.3 says that the above is ill-formed; 但是,IntelliJ 14.1.3表示以上内容格式错误; specifically, IntelliJ claims the attribute 'uriStartString' is not allowed and that 'rewriteURI' is missing the 'uriIdStartString' Attribute. 具体来说,IntelliJ声称不允许使用属性'uriStartString',并且'rewriteURI'缺少'uriIdStartString'属性。 That is, IntelliJ expects this: 也就是说,IntelliJ期望这样:

<?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. Apache XML Resolver 1.2库无法处理这种形式。

Who to trust: IntelliJ? 谁值得信任:IntelliJ? OASIS? 绿洲? Apache XML Resolver? Apache XML解析器?

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). OASIS XML目录规范1.0在[2]和附录B中使用“ uriStartString”(非规范),但在附录A中使用“ uriIdStartString”(非规范)并没有帮助。

It would be great if Norm Welch could comment on this; 如果Norm Welch可以对此发表评论,那就太好了; after all he wrote the OASIS XML Catalog spec and has been involved in the Apache XML Resolver implementation. 毕竟,他写了OASIS XML Catalog规范,并参与了Apache XML Resolver的实现。

[1] https://www.oasis-open.org/committees/entity/spec-2001-08-06.html#s.rewritesystem [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 [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 [3] https://www.oasis-open.org/committees/entity/spec-2001-08-06.html#element-rewriteURI

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM