【问题标题】:IntelliJ Idea: Schemas and DTDs / configuring XML catalogIntelliJ Idea:模式和 DTD / 配置 XML 目录
【发布时间】:2014-12-12 17:05:53
【问题描述】:

我的项目中有很多 xml 文件,这些文件是用许多 xsd 模式文件描述的。 XSD 模式使用复杂的命名空间结构,我想配置 IDE (IntelliJ Idea) 以在我的本地文件系统 (https://www.jetbrains.com/idea/help/xml-catalog.html) 上解析这些模式的 URI。 所以我打开 Idea Settings,选择 Language & Frameworks -> Schemas and DTDs -> XML Catalog 并指向 xml-catalog.properties 文件的路径,内容如下:

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

接下来我创建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>

我希望 Idea 会在我的本地目录 c:/Projects/MyProject/schemas 中解析所有前缀为 http://www.mycompany.com/schemas 的模式,并将它们用于验证和代码突出显示。但是编辑器中的所有 URI 仍然是红色的...... 在xml-catalog.xml 中搜索和使用路径、URI 和指令对我没有任何结果...

谁能向我展示有助于解析至少一个 URI 或公共/系统的有效 XML 目录设置,或者向我指出执行此操作的详细手册?..

【问题讨论】:

    标签: intellij-idea xsd resolver xmlcatalog


    【解决方案1】:

    根据 OASIS XML 目录规范 [1],您的示例应该如下工作:

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

    改写为:

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

    您是否尝试过使用“rewriteURI”[2] 而不是“rewriteSystem”[1]?

    这是我们多年来在 JPL 广泛使用的一个示例。至少,我知道这在 linux 和 macosx 上可靠地工作;但是,我对 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>
    

    使用 Apache XML Resolver 1.2 库实现 [3],上面重写了以下 URI:

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

    到:

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

    但是,IntelliJ 14.1.3 表示上述格式不正确;具体来说,IntelliJ 声称不允许使用“uriStartString”属性,并且“rewriteURI”缺少“uriIdStartString”属性。也就是说,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>
    

    Apache XML Resolver 1.2 库不处理这种形式。

    值得信赖的人:IntelliJ?绿洲? Apache XML 解析器?

    OASIS XML 目录规范 1.0 在 [2] 和附录 B(非规范)中使用“uriStartString”,但在附录 A(非规范)中使用“uriIdStartString”,这并没有帮助。

    如果 Norm Welch 能对此发表评论,那就太好了;毕竟他编写了 OASIS XML Catalog 规范并参与了 Apache XML Resolver 的实现。

    [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

    【讨论】:

    • 感谢您的回答。我更新了 Idea,当前版本是 14.1.3。我的问题配置()现在对我有用。但任何更改都需要重新启动 IDE (!)。
    猜你喜欢
    • 2013-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-10
    • 1970-01-01
    • 2019-10-25
    • 2019-01-04
    • 1970-01-01
    相关资源
    最近更新 更多