xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andy_C...@tertio.com
Subject Re: Problems finding schema definition
Date Thu, 07 Sep 2000 13:35:20 GMT
Thanks for the replies.  Andy, I took your thorough advice but am getting
another error.   The top of my XML looks like:

line 1:  <?xml version="1.0" ?>
line 2:
line 3:  <GMI xmlns='NS'
line 4:      xmlns:xsi='http://www.w3.org/1999/XMLSchema-instance'
line 5:      xsi:schemaLocation='NS GMI.xsd'>

and the error I get is:

    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
    [Error] GMIwithSchema.xml:5:38:Schema error: complexType '#0' with a elementOnly or mixed
content need to have at least one particle child.

Some questions:

Is the error in my XML file (as suggested by the fact that the error is on line 5 of my XML
file,) or my XSD file (as suggested by the fact that it is
 a "Schema error")?
I have no '#0' in my schema file so how can it cause an error?
What is a particle child?  I have searched various XML resources for this but with no luck.
Is there a list of parser error messages somewhere and an explanation of what they mean?

Again, any assistance is appreciated.



Andy Clark <andyc@apache.org> on 06/09/2000 18:38:50

Please respond to general@xml.apache.org

To:   general@xml.apache.org
Subject:  Re: Problems finding schema definition

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.xsd -->
  <schema xmlns='http://www.w3.org/1999/XMLSchema'
   <element name='root'>
     <element ref='sub'/> <!-- WRONG -->
   <element name='sub'/>

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'>
     <element ref='a:sub'/> <!-- RIGHT -->
   <element name='sub'/>

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

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

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'
        xsi:schemaLocation='NS grammar.xsd'>

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

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

View raw message