如何通过相对路径引用本地 XSD 文件

How to Reference Local XSD File By Relative Path(如何通过相对路径引用本地 XSD 文件)

本文介绍了如何通过相对路径引用本地 XSD 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是 如何配置 Eclipse 以使用的后续内容`ehcache` 并且在 如何正确引用本地 XML Schema 文件?

由于不再托管 xsd 文件,我从存档中下载了它的副本.我已将该文件放在我的资源目录中,并希望在我的 xsi:schemaLocation 中从我的项目的相对路径中引用它.我们有 windows 和 mac 开发人员,所以像 file:///c:/project/foo 这样的绝对路径约定是行不通的.

Since the xsd file is not longer being hosted, I downloaded a copy of it from the archive. I've put the file in my resource directory and would like to reference it in my xsi:schemaLocation from a relative path of my project. We have both windows and mac developers, so an absolute path convention like file:///c:/project/foo won't work.

相对路径的另一种替代方法是,如果有一种方法可以引用 windows 和 mac 的系统属性,那么我可以执行 2 个条目,例如 file:///$HOME/workspace/foo.

Another alternative to relative path would be if there is a way to reference system properties for both windows and mac, then I could do 2 entries like file:///$HOME/workspace/foo.

我的 Mac 上的项目存在于 ~/workspace/foo 中,$HOME 的 echo 给出了我的主路径.

My project on my mac exists in ~/workspace/foo and echo of $HOME gives my home path.

我的spring-cache.xml存在于./src/main/webapp/WEB-INF/spring/

我的 ehcache-spring-1.2.xsd 存在于 ./src/main/resources/

以下是我尝试过但没有成功的一些:

The following are some that I've tried without success:

        file:///$HOME/workspace/foo/src/main/resources/ehcache-spring-1.2.xsd
        file:///./src/main/resources/ehcache-spring-1.2.xsd             
        file:///../../../../resources/ehcache-spring-1.2.xsd
        file:///../../../../resources/ehcache-spring-1.2.xsd
        ../../../../resources/ehcache-spring-1.2.xsd
        file://../../../../resources/ehcache-spring-1.2.xsd
        file://$HOME/workspace/foo/src/main/resources/ehcache-spring-1.2.xsd
        file://./src/main/resources/ehcache-spring-1.2.xsd              
        file://../../../../resources/ehcache-spring-1.2.xsd

我似乎也有问题让它从绝对路径引用文件,所以也许有不同的方式来引用 mac 上的文件?例如以下方法无效:

I also seem to have issues getting it to reference the file from absolute path too, so perhaps there is a different way to reference the file on mac? e.g. The following did not work:

file:///Users/me/workspace/foo/src/main/resources/ehcache-spring-1.2.xsd
file:////Users/me/workspace/foo/src/main/resources/ehcache-spring-1.2.xsd
file://Users/me/workspace/foo/src/main/resources/ehcache-spring-1.2.xsd

推荐答案

认为我的问题是 webapp 目录可能无法查看资源文件夹.

Think my issue was that the webapp dir may not have visibility to the resources folder.

我这样说是因为基于对以下堆栈溢出问题的阅读,看起来相对路径的东西应该非常直截了当:带有 XML Schema 本地副本的 XML 文件 和 如何在 XML 文档中使用本地机器上的 Schema

I say this because based on the reading of the following stack overflow questions, it looks like the relative path stuff should be pretty straigh forward: XML File with local copy of XML Schema and How to use Schema that is on local machine in XML document

然后我尝试暴力破解引用,以防它与部署目录或类路径有关,并且以下所有操作都失败了:

I then tried to brute force the references, in case it was something with deploy directory or class path, and all of the following failed:

../../../../resources/ehcache-spring-1.2.xsd
../../../resources/ehcache-spring-1.2.xsd
../../resources/ehcache-spring-1.2.xsd
../resources/ehcache-spring-1.2.xsd
./resources/ehcache-spring-1.2.xsd
../ehcache-spring-1.2.xsd
./ehcache-spring-1.2.xsd

解决办法:

但是,通过将 xsd 文件从 ./src/main/resources/ 移动到 ./src/main/webapp/WEB-INF/spring/ 我当时只需 ehcache-spring-1.2.xsd

However by moving the xsd file from ./src/main/resources/ to ./src/main/webapp/WEB-INF/spring/ I was then able to reference it correctly/easily by just ehcache-spring-1.2.xsd

这篇关于如何通过相对路径引用本地 XSD 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何通过相对路径引用本地 XSD 文件