如何正确引用本地 XML 架构文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19253402/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to reference a local XML Schema file correctly?
提问by Arturas M
I'm having this problem with referencing my XML Schema in an XML file.
我在 XML 文件中引用我的 XML 架构时遇到了这个问题。
I have my XSD in this path:
我在这条路径中有我的 XSD:
C:\environment\workspace\maven-ws\ProjectXmlSchema\email.xsd
But when in my XML file I'm trying to locate the schema like this, the XSD is not found:
但是当我在我的 XML 文件中尝试定位这样的架构时,找不到 XSD:
<?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">
The only way the XSD is found is when it's in the same folder:
找到 XSD 的唯一方法是当它位于同一文件夹中时:
xsi:schemaLocation="http://www.w3schools.com email.xsd"
So the question is this: How does the path have to look so that the XSD will be found if the XML file wasn't in the same folder as the XSD file?
所以问题是这样的:如果 XML 文件与 XSD 文件不在同一个文件夹中,那么路径必须如何查找才能找到 XSD?
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.
顺便说一句,我一直在使用的示例来自MSDN:他们声称它应该按照我尝试的方式工作。但事实并非如此。
采纳答案by kjhughes
Add one more slash after file://in the value of xsi:schemaLocation. (You have two; you need three. Think protocol://host/pathwhere protocolis 'file'and hostis 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.
file://在 的值后面再添加一个斜杠xsi:schemaLocation。(你有两个;你需要三个。想想protocol://host/path这里protocol是哪里'file'和哪里是host空的,连续产生三个斜线。)你也可以消除 . 上的双斜线path。我相信双斜杠有助于文件系统允许文件名和目录名中有空格,但您明智地避免了路径命名中的这种复杂性。
xsi:schemaLocation="http://www.w3schools.com file:///C:/environment/workspace/maven-ws/ProjextXmlSchema/email.xsd"
Still not working?I suggest that you carefully copy the full file specification for the XSD into the address bar of Chrome or Firefox:
还是行不通?我建议您将 XSD 的完整文件规范仔细复制到 Chrome 或 Firefox 的地址栏中:
file:///C:/environment/workspace/maven-ws/ProjextXmlSchema/email.xsd
file:///C:/environment/workspace/maven-ws/ProjextXmlSchema/email.xsd
If the XSD does notdisplay 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,请删除路径的最后一个组件(email.xsd),然后查看是否无法显示父目录。以这种方式继续,沿着目录结构向上走,直到您发现路径与本地文件系统的实际情况不同的地方。
If the XSD doesdisplayed 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.
如果 XSD确实显示在浏览器中,请说明您使用的 XML 处理器,并准备好听到它已损坏或您必须解决某些限制。我可以告诉您,上述修复程序适用于我的基于 Xerces-J 的验证器。
回答by gamoz
Maybe can help to check that the path to the xsd file has not 'strange' characters like 'é', or similar: I was having the same issue but when I changed to a path without the 'é' the error dissapeared.
也许可以帮助检查 xsd 文件的路径是否没有像“é”或类似的“奇怪”字符:我遇到了同样的问题,但是当我更改为没有“é”的路径时,错误消失了。
回答by Developer
If you work in MS Visual Studiojust do following
如果您在MS Visual Studio 中工作,请执行以下操作
- Put WSDL file and XSD file at the same folder.
Correct WSDL file like this YourSchemeFile.xsd
Use visual Studio using this great example How to generate service reference with only physical wsdl file
- 将 WSDL 文件和 XSD 文件放在同一文件夹中。
更正像这样的 WSDL 文件YourSchemeFile.xsd
使用 Visual Studio using this great example How to generate service reference with only physical wsdl file
Notice that you have to put the path to your WSDL file manually. There is no way to use Open Filedialog box out there.
请注意,您必须手动放置 WSDL 文件的路径。没有办法在那里使用“打开文件”对话框。

