Java 如何在 xsd 文件中指定架构位置?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2872264/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 13:54:05  来源:igfitidea点击:

How to specify schema location in an xsd file?

javaxmlweb-servicesxsd

提问by Manoj

I have an xsd file Foo.xsd. I tried following ways to refer it in a WSDL file but it doesnt work.

我有一个 xsd 文件 Foo.xsd。我尝试了以下方法在 WSDL 文件中引用它,但它不起作用。

1) placed the xsd file in local file system and imported it as

1) 将 xsd 文件放在本地文件系统中并将其导入为

<xsd:import namespace="http://ws.test.com/" schemaLocation="file:///D:/wsdl/Foo.xsd"></xsd:import>

2) Placed the xsd file in web root folder and imported as

2) 将 xsd 文件放在 web 根文件夹中并导入为

<xsd:import namespace="http://ws.test.com/" schemaLocation="http://localhost:8080/Xfire/Foo.xsd"></xsd:import>

When I run the client I get null for the fields of response object. But this works when I embed the type definition inside the WSDL itself.

当我运行客户端时,响应对象的字段为空。但是当我将类型定义嵌入 WSDL 本身时,这会起作用。

How do we specify the path to external xsds?

我们如何指定外部 xsds 的路径?

I am using xFire 1.2.6 for generating webservices. Client is generated using xFire WSGen ant task.

我正在使用 xFire 1.2.6 来生成网络服务。客户端是使用 xFire WSGen 蚂蚁任务生成的。

采纳答案by Arne Burmeister

The WSDL is accessed by HTTP from any host, so the client can neither access a file URL nor the localhost (which will be its own host, not your server). The best solution will be a file path to the xsd file:

WSDL 可以从任何主机通过 HTTP 访问,因此客户端既不能访问文件 URL,也不能访问本地主机(它将是它自己的主机,而不是您的服务器)。最好的解决方案是 xsd 文件的文件路径:

Relative path:

相对路径:

<xsd:import namespace="http://ws.test.com/" schemaLocation="../Foo.xsd"/>

Absolute path:

绝对路径:

<xsd:import namespace="http://ws.test.com/" schemaLocation="/myapp/Foo.xsd"/>

For the absolute path you need to know the context path of your webapp, so I would prefer the relative path.

对于绝对路径,您需要知道 web 应用程序的上下文路径,所以我更喜欢相对路径。