understanding noNamespaceSchemaLocation

C

cartoper

XML, Schemas, and XSLT has been part of my life for a number of years
now, but I have always used it in desktop application where I simply
make the noNamespaceSchemaLocation attribute the name of the schema
because it is going to reside in the same location as the xml file.

I am now working on a project that is a bit more complex. Again part
is a desktop application which will not have access to the Internet all
the time, but another part of the project does have access to the
Internet. It is my understanding that within the XML, it is possible
to provide a URL as the namespace name.

How exactly do I go about setting up the XML so that when it is
validated on the desktop application, I can simply provide the schema
like I always have and then on the web it uses the URL as the source.

I don't think my question makes any sense. What I am really looking
for is a good tutorial on just namespaces and how they work. Any
suggestions?
 
P

Peter Flynn

XML, Schemas, and XSLT has been part of my life for a number of years
now, but I have always used it in desktop application where I simply
make the noNamespaceSchemaLocation attribute the name of the schema
because it is going to reside in the same location as the xml file.

I am now working on a project that is a bit more complex. Again part
is a desktop application which will not have access to the Internet all
the time, but another part of the project does have access to the
Internet. It is my understanding that within the XML, it is possible
to provide a URL as the namespace name.

It's the other way around: a namespace name MUST be a URI. The URI
syntax allows for interpretation as a local filename, either relative to
the current location or absolute to your local hard disk, or as a
network resource (starting with http://, ftp://, etc)...however, the use
of local names is deprecated in namespaces.

I'm afraid noNamespaceSchemaLocation is just an unpleasant kludge: the
Namespaces Spec says "It is not a goal that it [the namespace name] be
directly usable for retrieval of a schema (if any exists)."
How exactly do I go about setting up the XML so that when it is
validated on the desktop application, I can simply provide the schema
like I always have and then on the web it uses the URL as the source.

You need to ask your software manufacturer for any non-standard feature
they may have provided. It's also a bit risky. What happens if the local
copy and the network copy go out of sync?

It's a great pity Schemas were not implemented using the DOCTYPE
declaration like DTDs, then we would have had PUBLIC and SYSTEM catalog
resolution at our disposal. Unfortunately this would have entailed
another TC to ISO 8879 and another tedious decade teaching developers
how to do catalog resolution properly.

///Peter
 
C

cartoper

Peter said:
XML, Schemas, and XSLT has been part of my life for a number of years
now, but I have always used it in desktop application where I simply
make the noNamespaceSchemaLocation attribute the name of the schema
because it is going to reside in the same location as the xml file.

I am now working on a project that is a bit more complex. Again part
is a desktop application which will not have access to the Internet all
the time, but another part of the project does have access to the
Internet. It is my understanding that within the XML, it is possible
to provide a URL as the namespace name.

It's the other way around: a namespace name MUST be a URI. The URI
syntax allows for interpretation as a local filename, either relative to
the current location or absolute to your local hard disk, or as a
network resource (starting with http://, ftp://, etc)...however, the use
of local names is deprecated in namespaces.

I'm afraid noNamespaceSchemaLocation is just an unpleasant kludge: the
Namespaces Spec says "It is not a goal that it [the namespace name] be
directly usable for retrieval of a schema (if any exists)."

Peter,

First off, thank you for your help! I am guessing here, but my
impression is thta things work this way:

Xml with a namespace of: urn:/cartoper/schema1
actual schema name: MyFirstSchema.xsd

When loading MyFirstSchema.xsd into the validator, there will be a way
to tell the validator that it's namespace is urn:/cartoper/schema1.

Or is it that I have to place the urn:/cartoper/schema1 in the schema,
too?
 
M

Martin Honnen

Xml with a namespace of: urn:/cartoper/schema1
actual schema name: MyFirstSchema.xsd

When loading MyFirstSchema.xsd into the validator, there will be a way
to tell the validator that it's namespace is urn:/cartoper/schema1.

Or is it that I have to place the urn:/cartoper/schema1 in the schema,
too?

If you want to author a schema defining elements in that namespace then
use targetNamespace="urn:/cartoper/schema1" e.g.

<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:/cartoper/schema1"
elementFormDefault="qualified">
 
C

cartoper

If you want to author a schema defining elements in that namespace then
use targetNamespace="urn:/cartoper/schema1" e.g.

<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:/cartoper/schema1"
elementFormDefault="qualified">

Martin,

Ok, that makes perfect sense, after doing some digging;) The final
questions is: What exactly do I put in the XML? I am using XMLSpy as
my editor. When I assign the schema to the xml file, it generates this
attributes to the root element:

xmlns="urn:/cartoper/schema1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:/cartoper/schema1 D:\<full
path>\MyFirstSchema.xsd"

When I removed the full path from the xsi:schemaLocation attribute
(xsi:schemaLocation="urn:/cartoper/schema1 MyFirstSchema.xsd"), XmlSpy
complains that it is not valid. Do I simply need to leave off the
xsi:schemaLocation? Or is there some way I can still have the xml
point to the schema being in the same directory? I sort of like how
XMLSpy will validate the XML for me, I use it mostly in development.
 
C

cartoper

Anyone?

Martin,

Ok, that makes perfect sense, after doing some digging;) The final
questions is: What exactly do I put in the XML? I am using XMLSpy as
my editor. When I assign the schema to the xml file, it generates this
attributes to the root element:

xmlns="urn:/cartoper/schema1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:/cartoper/schema1 D:\<full
path>\MyFirstSchema.xsd"

When I removed the full path from the xsi:schemaLocation attribute
(xsi:schemaLocation="urn:/cartoper/schema1 MyFirstSchema.xsd"), XmlSpy
complains that it is not valid. Do I simply need to leave off the
xsi:schemaLocation? Or is there some way I can still have the xml
point to the schema being in the same directory? I sort of like how
XMLSpy will validate the XML for me, I use it mostly in development.
 
M

Martin Honnen


You might want to ask XMLSpy specific questions in an XMLSpy user forum
as there you have a better chance to find other users of that software
than in a generic comp.text.xml group.
 
C

cartoper

Martin said:
You might want to ask XMLSpy specific questions in an XMLSpy user forum
as there you have a better chance to find other users of that software
than in a generic comp.text.xml group.

Martin,

I would agree with you, except, I am trying to understand how exactly
namespaces, schemas, and xml are all tied together, I am assuming the
XMLSpy will comply with the way things are, which is not always the
case;)

Peter's inital reply implies that it is a bad thing to use the
xsi:schemaLocation attribute. Am I correct? Is there any way of
denoting in the xsi:schemaLocation that the schema file is in the same
folder/directory as the XML?
 

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
474,007
Messages
2,570,266
Members
46,865
Latest member
AveryHamme

Latest Threads

Top