How to specify schema location in an xsd file?
java, web-services, xml, xsd
Solution
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:
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.
Problem
I have an xsd file Foo.xsd. I tried following ways to refer it in a WSDL file but it doesnt work. 1) placed the xsd file in local file system and imported it as ``` <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 ``` <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. How do we specify the path to external xsds? I am using xFire 1.2.6 for generating webservices. Client is generated using xFire WSGen ant task.