You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xml.apache.org by An...@tertio.com on 2000/09/06 16:51:11 UTC

Problems finding schema definition

I have written an XML schema (that makes use of the standard XML Schema
definitions) but am having zero success in getting the parser to find my
schema definition file.

The top of my XML file looks like:

    <?xml version="1.0" ?>
    <GMI xmlns="file:///H:/Andy/Programs/Web/XML/GMI.xsd">
      <ServiceTag>CSO</ServiceTag>
       ...etc...

The top of my XSD file (H:/Andy/Programs/Web/XML/GMI.xsd) looks like:

    <?xml version="1.0" ?>
    <schema xmlns="http://www.w3.org/1999/XMLSchema">
    <element name="GMI">
    ...etc...

I'm using the DOMcount Java sample program that I believe has a built-in parser and XML Schema definitions.

When I run:

    java -cp C:\XML\xerces-1_1_3\xerces.jar;C:\XML\xerces-1_1_3\xercesSamples.jar dom.DOMCount -v file:///H:/Andy/Programs/Web/XML/GMI.xml

I get a bunch of errors, starting with:

    java -cp C:\XML\xerces-1_1_3\xerces.jar;C:\XML\xerces-1_1_3\xercesSamples.jar dom.DOMCount -v file:///H:/Andy/Programs/Web/XML/GMI.xml
    file:///H:/Andy/Programs/Web/XML/GMI.xsd grammar not found
    [ERROR] GMI.xml:3:55: Element type "GMI" must be declared.
    ...etc...

I am new to XML.  Am I doing something stupid?

Andy

PS. I would have scanned the mailing list archive first but it is currently unavailable.

Tertio Limited  -  One Angel Square,   Torrens Street,   London  EC1V 1PL
Tel: +44 (0)20 7843 4000 Fax: +44 (0)20 7843 4001 Web http://www.tertio.com
Any views expressed in this message are those of the individual sender,
except where the sender specifically states them to be the views of Tertio Ltd.


Re: Problems finding schema definition

Posted by "Thomas B. Passin" <tp...@mitretek.org>.
<An...@tertio.com> asked

> I have written an XML schema (that makes use of the standard XML
Schema
> definitions) but am having zero success in getting the parser to find
my
> schema definition file.
>
> The top of my XML file looks like:
>
>     <?xml version="1.0" ?>
>     <GMI xmlns="file:///H:/Andy/Programs/Web/XML/GMI.xsd">
>       <ServiceTag>CSO</ServiceTag>
>        ...etc...
I don't know how Xerces finds schemas, but a namespace declaration does
not have anything to do with assigning schemas or anything else.  It
only gives you a way to distinguish names that might otherwise be taken
to be the same.  You definitely don't want something as changeable as a
file location on your own machine to be a namespace designator.

Tom Passin


Re: Problems finding schema definition

Posted by Andy Clark <an...@apache.org>.
Andy_Carr@tertio.com wrote:
>     <GMI xmlns="file:///H:/Andy/Programs/Web/XML/GMI.xsd">
> [...]
>     <schema xmlns="http://www.w3.org/1999/XMLSchema">

Okay, there are two problems with your XML and XSD files.

1) Your XML file is in a namespace but your XML Schema grammar
doesn't specify a target namespace. If your document instance
is in a namespace, then your grammar has to specify a target
namespace and the two must match! Here's an example of a 
grammar:

  <!-- grammar.xsd -->
  <schema xmlns='http://www.w3.org/1999/XMLSchema'
          targetNamespace='NS'>
   <element name='root'>
    <complexType>
     <element ref='sub'/> <!-- WRONG -->
    </complexType>
   </element>
   <element name='sub'/>
  </schema>

However, this leads to a common problem. When you specify a
target namespace in your XML Schema document, then all of the
references to element types and attribute groups are QNames!
What does this mean? This means that my example is wrong.

The Schema processor will look at "sub" as a qualified name
so it thinks that you are referring to an element declared
in the default namespace. And since I have bound the default
namespace to "http://www.w3.org/1999/XMLSchema", it will look
in *that* grammar for an element called "sub".

So how do we avoid this problem? Well, we have to fully
qualify the "sub" element reference which, in turn, means
that we need to bind that namespace. Here's the fix:

  <!-- grammar.xsd -->
  <schema xmlns='http://www.w3.org/1999/XMLSchema'
          xmlns:a='NS' targetNamespace='NS'>
   <element name='root'>
    <complexType>
     <element ref='a:sub'/> <!-- RIGHT -->
    </complexType>
   </element>
   <element name='sub'/>
  </schema>

Notice that the prefix "a" is bound to *exactly* the same
namespace string as is specified in the targetNamespace
attribute!

Now on to your second problem...

2) The namespace binding is not the way in which that you 
tell the XML Schema processor to find your Schema grammar. The
namespace is only a means of uniquely qualifying a namespace.
So the following is incorrect.

  <!-- document.xml -->
  <root xmlns='NS'> <!-- WRONG -->
   <sub/>
  </root>

First you have to bind the XML Schema instance document
namespace and then use the special attribute "schemaLocation"
in order to locate your grammar. (The specification says
that this is only a "hint" but who are they kidding...) The
value of schemaLocation is a set of tuples: each tuple is a
pair of namespace and grammar location. For example:

  <!-- document.xml -->
  <root xmlns='NS' 
        xmlns:xsi='http://www.w3.org/1999/XMLSchema-instance'
        xsi:schemaLocation='NS grammar.xsd'>
   <sub/>
  </root>

Also, you probably shouldn't use 'file:///.../GMI.xsd' as 
your namespace binding; it's really the location of your 
grammar and should only be used in the xsi:schemaLocation 
or xsi:noNamespaceSchemaLocation attribute.

Some disclaimers:

a) Schema is confusing so if I've made any mistakes in the
   above examples, someone please correct me.
b) I really shouldn't be using "NS" as my namespace binding.
   I'm only using it to simplify my example; otherwise
   *everything* is a URI and confuses the person trying to
   figure out what's related to what.

-- 
Andy Clark * IBM, JTC - Silicon Valley * andyc@apache.org

Re: Problems finding schema definition

Posted by "Thomas B. Passin" <tp...@mitretek.org>.
Keith Kyzivat wrote -

> I encountered this as well when I started...
> File URLs seem to be a problem...  Java seems to like them one way,
while
> wininet (and then also internet explorer) like a different style of
file
> url...  It seems as if there is no standard for the format of a file
url...
>
It's often because the RFC for url format isn't quite clear enough for a
file url on a windows machine.  You could try the old browser style:

 file:///c|/dir1/dir2

I've never been able to find documentation about using "|" instead of
":", and the colon is supposed to be legal, but a lot of code wants to
see it anyway.  Also, path separators are supposed to be forward slashes
(even for Windows paths) - although both IE and Netscape browsers are
very tolerant about the file:// url format.

Another thing that's supposed to work for a local file is

file://localhost/path/to/the/file

But what actually works with any piece of code is anyone's guess.  Just
keep trying the possibilities.

So you could try the above formats and see if they work. But it's still
not desirable for use as a namspace urn.

Tom Passin



RE: Problems finding schema definition

Posted by Keith Kyzivat <kk...@iconverse.com>.
I encountered this as well when I started...
File URLs seem to be a problem...  Java seems to like them one way, while
wininet (and then also internet explorer) like a different style of file
url...  It seems as if there is no standard for the format of a file url...

I cured my problem with it by just installing a web server on my machine
(apache does the trick), and then referencing the dtd (or xsd in this case)
by putting it in the web docs path, and replacing the file url with a full
http url.

Can anyone say something about file URLs, and how to make them
interoperable?

Thanks,
Keith

-----Original Message-----
From: Andy_Carr@tertio.com [mailto:Andy_Carr@tertio.com]
Sent: Wednesday, September 06, 2000 10:51 AM
To: general@xml.apache.org
Subject: Problems finding schema definition


I have written an XML schema (that makes use of the standard XML Schema
definitions) but am having zero success in getting the parser to find my
schema definition file.

The top of my XML file looks like:

    <?xml version="1.0" ?>
    <GMI xmlns="file:///H:/Andy/Programs/Web/XML/GMI.xsd">
      <ServiceTag>CSO</ServiceTag>
       ...etc...

The top of my XSD file (H:/Andy/Programs/Web/XML/GMI.xsd) looks like:

    <?xml version="1.0" ?>
    <schema xmlns="http://www.w3.org/1999/XMLSchema">
    <element name="GMI">
    ...etc...

I'm using the DOMcount Java sample program that I believe has a built-in
parser and XML Schema definitions.

When I run:

    java -cp
C:\XML\xerces-1_1_3\xerces.jar;C:\XML\xerces-1_1_3\xercesSamples.jar
dom.DOMCount -v file:///H:/Andy/Programs/Web/XML/GMI.xml

I get a bunch of errors, starting with:

    java -cp
C:\XML\xerces-1_1_3\xerces.jar;C:\XML\xerces-1_1_3\xercesSamples.jar
dom.DOMCount -v file:///H:/Andy/Programs/Web/XML/GMI.xml
    file:///H:/Andy/Programs/Web/XML/GMI.xsd grammar not found
    [ERROR] GMI.xml:3:55: Element type "GMI" must be declared.
    ...etc...

I am new to XML.  Am I doing something stupid?

Andy

PS. I would have scanned the mailing list archive first but it is currently
unavailable.

Tertio Limited  -  One Angel Square,   Torrens Street,   London  EC1V 1PL
Tel: +44 (0)20 7843 4000 Fax: +44 (0)20 7843 4001 Web http://www.tertio.com
Any views expressed in this message are those of the individual sender,
except where the sender specifically states them to be the views of Tertio
Ltd.


---------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org