Re: I am having a problem with using XSD & XSL in the same document

Hi Boris,

> Would changing:
> <FamilyTree xmlns="http://www.kortiak.com/namespace"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://www.kortiak.com/namespace
> FamilyTree.xsd">
>
> To:
> <FamilyTree xsi:schemaLocation="http://www.kortiak.com/namespace
> FamilyTree.xsd">
>
> Also, resolve the problem? I really do not think I need the
> namespace at this point; I just want the XSD to work. Unless, of
> course, best practices would suggest that one create a namespace
> when possible to avoid future confusions. (I know, I know, try it
> and see, just kind of busy tonight. I will do it tomorrow, promise!)

No, for two reasons. First, the xsi:schemaLocation attribute indicates
what schema should be used to validate elements in a particular
namespace. The xsi:schemaLocation attribute:

  xsi:schemaLocation="http://www.kortiak.com/namespace
                      FamilyTree.xsd"

says "Look for element declarations for elements in the namespace
'http://www.kortiak.com/namespace' in FamilyTree.xsd". If you don't
have the default namespace declaration on your document element, then
the elements in your XML document aren't in that namespace, so the
schema won't be used for them.

To point to a schema to be used for elements in no namespace (as your
elements would be because there's no default namespace declaration),
you should use xsi:noNamespaceSchemaLocation:

<FamilyTree xsi:noNamespaceSchemaLocation="FamilyTree.xsd">
  ...
</FamilyTree>

That will get the processor to look at FamilyTree.xsd for the
declarations.

But then the second problem comes into play. Each schema is tied to a
particular "target namespace". Your schema probably looks like:

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

The targetNamespace attribute indicates the namespace for all the
things that are declared or defined at the top level of the schema,
such as elements, complex types and attribute groups. In the above
case, the elements that the schema declares are those in the namespace
'http://www.kortiak.com/namespace'.

If you want to change this so that the schema has no target namespace,
then remove the targetNamespace attribute and remove the default
namespace declaration, so you end up with:

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

With these two changes, you should be able to use the schema to
validate your XML document without the namespace declaration.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

Received on Thursday, 24 October 2002 05:09:33 UTC