XMLSchema and XML Validation problem

R

Robert Ludewig

This is my XML Schema (Sitemap.xsd) :

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.htw-dresden.de/SitemapNS">
<xs:element name="Sitemap">
<xs:complexType>
<xs:all>
<xs:element name="Page">
<xs:complexType>
<xs:all>
<xs:element minOccurs="1" name="Title" type="xs:normalizedString"/>
<xs:element minOccurs="0" name="Description" type="xs:string"/>
<xs:element minOccurs="0" name="Linklist">
<xs:complexType>
<xs:sequence>
<xs:element name="Link" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="ID" type="xs:IDREF" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:all>
<xs:attribute name="ID" type="xs:ID" use="required"/>
</xs:complexType>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>

And when I define a new XML file using this xsd it does not Validate:

<Sitemap xmlns="http://www.htw-dresden.de/SitemapNS"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.htw-dresden.de/SitemapNS Sitemap.xsd">
<Page>
</Page>
</Sitemap>

XMLSpy says: unexpected child element: <Page>
MSXML4 says: the content is not valid, expected: <Page>

WHY does that happen ?? Its a namespace problem right ? What am I doing
wrong ?
 
R

Robert Ludewig

And why ?
I would have expected that if I don't want the namespace specification to be
required, that I have to do it with unqualified.
But it seems its the other way around?

What exactly does that elementFormDefault="qualified" do then?
 
R

Richard Tobin

Robert Ludewig said:
And why ?

We need an FAQ. This question has been answered many times.
I would have expected that if I don't want the namespace specification to be
required, that I have to do it with unqualified.

Your Sitemap element has xmlns="http://www.htw-dresden.de/SitemapNS",
which makes that be the default namespace, so your unprefixed Page
element is in that namespace.

elementFormDefault="qualified" makes local element declarations apply
to elements in the target namespace (rather than in no namespace), which
is what you want.

Your schema would be right if your document looked like this:

<x:Sitemap xmlns:x="http://www.htw-dresden.de/SitemapNS"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.htw-dresden.de/SitemapNS Sitemap.xsd">
<Page>
</Page>
</x:Sitemap>

(i.e. if Page was in no namespace).

- 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,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top