Newbie: schema on local file system

M

maxwell

I'm trying to develop a schema, and test it on some sample data.
There are plenty of examples out there on how to develop schemas etc.,
but they all seem to assume that you give a URI for the schema that
points to a web address. For now, I do not have the schema in a web-
accessible place, it's just on the local file system. I'm stuck
trying to specify the xmlns inside the file.

If I have the schema in the same directory as the xml data file, I can
get away with the following first lines in the xml data file (that is,
it passes muster with xmllint)

<?xml version="1.0"?>
<Mo:MorphologicalData xmlns:Mo="Morph.xsd">...

But if I try for more generality--like putting all my schemas in a
single directory somewhere else--I can't seem to pull it off. That
is, if I replace the above couple lines in my xml data file with the
following:
<?xml version="1.0"?>
<Mo:MorphologicalData
xmlns:Mo="file:///home/mmaxwell/Data/LinguisticSchemas/
Morph.xsd">
--then xmllint gives me an error msg:
> /usr/bin/xmllint --noout --noent --schema Morph.xsd
MorphTestData.xml
MorphTestData.xml:4: element MorphologicalData: Schemas validity
error :
Element 'Mo:MorphologicalData': No matching global declaration
available.

(This is on a Linux file system, and I know the .xsd file exists in
the specified directory.)

I tried searching for "file:///" on line to get some examples of how
to do this, but all of the search engines I tried strip off the
":///", even though I quote it, so I get a bunch of irrelevant hits
with the word "file" in them. Just pointing me to some examples would
probably suffice.

Mike Maxwell
 
M

Martin Honnen

I'm trying to develop a schema, and test it on some sample data.
There are plenty of examples out there on how to develop schemas etc.,
but they all seem to assume that you give a URI for the schema that
points to a web address. For now, I do not have the schema in a web-
accessible place, it's just on the local file system. I'm stuck
trying to specify the xmlns inside the file.

I think you do not understand that a namespace is simply denoted by a
URL. There does not have to be any resource at that URL and usually or
at least often is not. So http://www.w3.org/1999/xhtml is the namespace
URL for XHTML 1. And http://www.w3.org/2000/svg the one for SVG 1.x.
Nevertheless while you can browser to those URLs you will not find a
schema there, just a HTML document giving some info on the namespace.

Schema location URL and namespace URL can be different.
 
U

usenet

If I have the schema in the same directory as the xml data file, I can
get away with the following first lines in the xml data file (that is,
it passes muster with xmllint)

<?xml version="1.0"?>
<Mo:MorphologicalData xmlns:Mo="Morph.xsd">...

But if I try for more generality--like putting all my schemas in a
single directory somewhere else--I can't seem to pull it off. That
is, if I replace the above couple lines in my xml data file with the
following:
<?xml version="1.0"?>
<Mo:MorphologicalData
xmlns:Mo="file:///home/mmaxwell/Data/LinguisticSchemas/
...

Although technically the namespace 'URI' is a URI, in practice it is
just treated as an opague string. Two namespace URIs are considered
the same if, after white space handling and entity expansion, they are
identical character-by-character. There is no attempt made to
dereference the URI.

For example, http://example.com, http://example.com/, http://www.example.com
and http://example.com/index.html may all result in the same resource
being shown. And if there happened to be a schema there, they would
all result in the same schema being returned. However, from a
namespace point of view they all represent different namespaces.

So you probably want to do something like:

<?xml version="1.0"?>
<Mo:MorphologicalData xmlns:Mo="http://mycompany.com/
Morph.xsd">...

If you want to specify in an XML instance how a schema is found, then
you can use the xsi:schemaLocation and xsi:noSchemaLocation
attributes, along the lines of:

<?xml version="1.0"?>
<Mo:MorphologicalData xmlns:Mo="http://mycompany.com/Morph.xsd"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xsi:schemaLocation=''file:///home/mmaxwell/Data/
LinguisticSchemas/Morph.xsd">...

This is optional though, and the schemaLocation is only considered to
be a 'hint'.

HTH,

Pete.
=============================================
Pete Cordell
Tech-Know-Ware Ltd
for XML to C++ data binding visit
http://www.tech-know-ware.com/lmx
(or http://www.xml2cpp.com)
=============================================
 
M

maxwell

If you want to specify in an XML instance how a schema is found, then
you can use the xsi:schemaLocation and xsi:noSchemaLocation
attributes, along the lines of:

<?xml version="1.0"?>
<Mo:MorphologicalData xmlns:Mo="http://mycompany.com/Morph.xsd"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xsi:schemaLocation=''file:///home/mmaxwell/Data/
LinguisticSchemas/Morph.xsd">...

This gives me a different error msg from xmllint:
MorphTestData.xml:7: element MorphologicalData:
Schemas validity error : Element 'Mo:MorphologicalData':
The attribute 'xsi:schemaLocation' is not allowed.
MorphTestData.xml fails to validate.
(Incidently, I'm assuming the line break between "Data/" and
"LinguisticSchemas/" is an artifact of email, although somewhere I
vaguely recall that the path and the filename were supposed to be
separated--not sure why??)
This is optional though, and the schemaLocation is only considered
to be a 'hint'.

A hint to whom or what? I was assuming that this was an _instruction_
to a validation program, but maybe I'm misunderstanding the purpose...

Mike Maxwell
 
U

usenet

This gives me a different error msg from xmllint:
MorphTestData.xml:7: element MorphologicalData:
Schemas validity error : Element 'Mo:MorphologicalData':
The attribute 'xsi:schemaLocation' is not allowed.
MorphTestData.xml fails to validate.

Ooops - cut and paste error on my part. I must have opened the wrong
version of the XSD spec. The xmlns:xsi attribute should be:

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

Sorry about that.
(Incidently, I'm assuming the line break between "Data/" and
"LinguisticSchemas/" is an artifact of email, although somewhere I
vaguely recall that the path and the filename were supposed to be
separated--not sure why??)

yep - e-mail artifact!
A hint to whom or what? I was assuming that this was an _instruction_
to a validation program, but maybe I'm misunderstanding the purpose...

It's a hint to the validation processor. It's along the lines of
"Look here for the schema, but if you don't find it there, don't
complain."

HTH,

Pete.
=============================================
Pete Cordell
Tech-Know-Ware Ltd
for XML to C++ data binding visit
http://www.tech-know-ware.com/lmx
(or http://www.xml2cpp.com)
=============================================
 
M

maxwell

Schema location URL and namespace URL can be different.

You're right, I totally didn't understand--thanks for the help!

Mike Maxwell
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top