I have an XML schema document (provided by a company I deal with) to validate a certain XML file that is required for their system.
Lets say the first couple of lines of the schema look like this (I have modified the URIs to protect the guilty!):
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
targetNamespace="http://www.example.com/manifest-plugin"
xmlns="http://www.example.com/manifest-plugin">
The URI in the XSD is not valid in the unmodified original i.e. you cannot go there to get a copy of this XSD file. I have no idea why they haven't published it at the URL defined in the XSD, but they haven't.
I have a local copy of the XSD which I would like to use to validate the XML file I create using the features of Eclipse's XML catalog. Obviously, as the URI is invalid there is no point to let the system try to retrieve the XSD from the web.
Let's say the local XSD file lives on my local drive here:
C:\xml_schemas\manifest-plugin.xsd
And the opening two lines of the XML file look like this:
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
Could anyone give an example of how to do this?
Specifically:
I have found this page on the Eclipse wiki, but I personally don't find the instructions very clear:-
Using the XML catalog in Eclipse
I have tried setting the XML catalog parameters thus:
Then adding
<manifest xmlns:targetNamespace="http://www.example.com/manifest-plugin">
to the XML file, but it doesn't seem to work.
By the way, if your version of Eclipse doesn't have the XML catalog, you probably haven't got the "web tools platform (WTP)" features installed. They come with the Java EE version of Eclipse, but can be installed separately.
If I'm not mistaken, you can specify a local schema location which will take precedence over the remote location of the XML Schema file.
As such, if you put your XSD file in the directory where your XML files are, the header of your manifest.xml file should be:
<manifest xmlns="http://my.super.xsd.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3schools.com manifest.xsd">
I tested under Eclipse, it works (you can even click on the XSD link). Now, that works if both your XSD and XML files are in the same directory.
If you want to have your XSD in a separate local location, you have to use the file
protocol. Given your example, your XML file would look like so:
<manifest xmlns="http://my.super.xsd.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3schools.com file:///C|/xml_schemas/manifest-plugin.xsd"">
This example also works under Eclipse, although when clicking on the XSD, it opens the web browser (at least for me).