Namespace in schema Question

K

kurtrips

Hi,

The schema tag (the root tag) of a schema file looks like

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

It is mentioned on many web pages across the net that
"the parser does not connect to the server and try to download the
document that's found at http://www.w3.org/2001/XMLSchema. Indeed
there may not be any such document".

So if this is only used as prefix, I may instead have
<xs:schema xmlns:xs="anything"
elementFormDefault="qualified">.

But when I validate my xml with this new xsd, I get "The element
'Books' is used but not declared in the DTD/Schema." It works fine in
case 1. (Books is the root element of my xml file).
Is this because this URL is hardcoded somewhere in the code of the
parser itself?
(I am using the MSXML 3.0 parser.)
 
J

Joe Kesselman

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
Is this because this URL is hardcoded somewhere in the code of the
parser itself?

Namespace URIs are meaningful even though there's often no "resource" at
the location they name. In this case, the specific URI being bound to
the xs: prefix is the one which is explicitly reserved for use in
defining schemas. If you use something else, this XML document is no
longer a schema document.

The whole point of namespaces is that they are named groups of names. If
you change the name of the group (the namespace URI), the names are no
longer part of that group.
 
K

kurtrips

Thanks for the prompt reply.

Joe said:
In this case, the specific URI being bound to
the xs: prefix is the one which is explicitly reserved for use in
defining schemas. If you use something else, this XML document is no
longer a schema document.

I do think that this *explicit reservation* is declared inside the
parser code. There's no other possible place.
 
J

Joe Kesselman

I do think that this *explicit reservation* is declared inside the
parser code. There's no other possible place.

Well, inside the schema processing code, which is usually but not
necessarily part of the parser per se, but why quibble.

The important thing is that it's declared in the schema spec. <grin/>
 
R

Richard Tobin

So if this is only used as prefix, I may instead have
<xs:schema xmlns:xs="anything"
elementFormDefault="qualified">.

But when I validate my xml with this new xsd, I get "The element
'Books' is used but not declared in the DTD/Schema." It works fine in
case 1. (Books is the root element of my xml file).
Is this because this URL is hardcoded somewhere in the code of the
parser itself?

Yes. That's how it distinguishes schema declarations from other things,
by their being in the namespace http://www.w3.org/2001/XMLSchema.
With your modified declaration, <xs:element name="Books"> is no longer
a schema declaration at all, so any <Books> elements are undeclared.

-- Richard
 

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,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top