如何正确引用本地 XML 架构文件? [英] How to reference a local XML Schema file correctly?

查看:42
本文介绍了如何正确引用本地 XML 架构文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 XML 文件中引用我的 XML 架构时遇到了这个问题.

I'm having this problem with referencing my XML Schema in an XML file.

我的 XSD 位于此路径中:

I have my XSD in this path:

C:\environment\workspace\maven-ws\ProjectXmlSchema\email.xsd

但是当我在我的 XML 文件中尝试定位这样的架构时,找不到 XSD:

But when in my XML file I'm trying to locate the schema like this, the XSD is not found:

<?xml version="1.0" encoding="UTF-8" ?>
    <email xmlns="http://www.w3schools.com"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.w3schools.com
                 file://C://environment//workspace//maven-ws//ProjextXmlSchema//email.xsd">

找到 XSD 的唯一方法是它在同一文件夹中:

The only way the XSD is found is when it's in the same folder:

           xsi:schemaLocation="http://www.w3schools.com email.xsd"

所以问题是:如果 XML 文件与 XSD 文件不在同一文件夹中,那么路径必须如何查找才能找到 XSD?

顺便说一下,我一直在使用的示例来自 MSDN:他们声称它应该像我尝试的那样工作.但它没有.

By the way, the example I've been using was from MSDN: they're claiming it's supposed to work the way I tried to. But it doesn't.

推荐答案

xsi:schemaLocation 的值中的 file:// 后多加一个斜线.(你有两个;你需要三个.想想 protocol://host/path 其中 protocol'file'host 此处为空,产生连续三个斜线.)您还可以消除沿 path 的双斜线.我相信双斜杠有助于文件系统允许文件名和目录名中有空格,但您明智地避免了路径命名中的这种复杂性.

Add one more slash after file:// in the value of xsi:schemaLocation. (You have two; you need three. Think protocol://host/path where protocol is 'file' and host is empty here, yielding three slashes in a row.) You can also eliminate the double slashes along the path. I believe that the double slashes help with file systems that allow spaces in file and directory names, but you wisely avoided that complication in your path naming.

xsi:schemaLocation="http://www.w3schools.com file:///C:/environment/workspace/maven-ws/ProjextXmlSchema/email.xsd"

还是不行?我建议你仔细将XSD的完整文件规范复制到Chrome或Firefox的地址栏中:

file:///C:/environment/workspace/maven-ws/ProjextXmlSchema/email.xsd

如果 XSD 没有在浏览器中显示,请删除路径的最后一个组件(email.xsd)之外的所有内容,看看是否无法显示父目录.以这种方式继续,沿着目录结构向上走,直到您发现路径与本地文件系统的实际情况不同.

If the XSD does not display in the browser, delete all but the last component of the path (email.xsd) and see if you can't display the parent directory. Continue in this manner, walking up the directory structure until you discover where the path diverges from the reality of your local filesystem.

如果 XSD 确实显示在浏览器中,请说明您使用的 XML 处理器,并准备好听到它已损坏或您必须解决一些问题局限性.我可以告诉您,上述修复程序适用于我的基于 Xerces-J 的验证器.

If the XSD does displayed in the browser, state what XML processor you're using, and be prepared to hear that it's broken or that you must work around some limitation. I can tell you that the above fix will work with my Xerces-J-based validator.

这篇关于如何正确引用本地 XML 架构文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆