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

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

问题描述

我在 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:environmentworkspacemaven-wsProjectXmlSchemaemail.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 Schema 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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