Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reference a local XML Schema file correctly?

Tags:

xml

xsd

I'm having this problem with referencing my XML Schema in an XML file.

I have my XSD in this path:

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 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:

           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?

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.

like image 768
Arturas M Avatar asked Oct 08 '13 16:10

Arturas M


People also ask

How do you reference an XML Schema?

Reference the XSD schema in the XML document using XML schema instance attributes such as either xsi:schemaLocation or xsi:noNamespaceSchemaLocation. Add the XSD schema file to a schema cache and then connect that cache to the DOM document or SAX reader, prior to loading or parsing the XML document.

Which attribute is used to reference an XML Schema?

The 'schemaLocation' attribute is used to reference XML Schema(s) that are defined in a target-namespace. The schemaLocation attribute can contain a list of namespaces and schema-locations, separated by white-space.

HOW include local XSD in XML?

For those of you wishing to reference a schema locally, you can easily launch the chrome web server plugin and point it to your schema's directory and then update your xml with the http address of the schema.


2 Answers

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" 

Still not working? I suggest that you carefully copy the full file specification for the XSD into the address bar of Chrome or Firefox:

file:///C:/environment/workspace/maven-ws/ProjextXmlSchema/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.

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.

like image 53
kjhughes Avatar answered Sep 25 '22 17:09

kjhughes


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.

like image 22
gamoz Avatar answered Sep 24 '22 17:09

gamoz