XMLSchema and XML Validation problem

Discussion in 'XML' started by Robert Ludewig, Jun 28, 2004.

  1. 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 ?
     
    Robert Ludewig, Jun 28, 2004
    #1
    1. Advertising

  2. In article <>,
    Robert Ludewig <> wrote:

    ><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    >targetNamespace="http://www.htw-dresden.de/SitemapNS">


    Add elementFormDefault="qualified".

    -- Richard
     
    Richard Tobin, Jun 28, 2004
    #2
    1. Advertising

  3. 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?
     
    Robert Ludewig, Jun 28, 2004
    #3
  4. In article <>,
    Robert Ludewig <> wrote:

    >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
     
    Richard Tobin, Jun 28, 2004
    #4
  5. Robert Ludewig wrote:

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


    Check the spec, for a start the examples in the primer:
    http://www.w3.org/TR/xmlschema-0/#QualLocals

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jun 28, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sudha
    Replies:
    0
    Views:
    372
    sudha
    Jun 30, 2003
  2. Marcin Wielgus

    XMLSchema, validation

    Marcin Wielgus, Mar 16, 2006, in forum: Java
    Replies:
    0
    Views:
    688
    Marcin Wielgus
    Mar 16, 2006
  3. AL
    Replies:
    4
    Views:
    379
    Henry S. Thompson
    Nov 8, 2005
  4. g.fiorentini

    PROBLEM: webservice, XmlNode return value, XMLSchema and WSDL

    g.fiorentini, Sep 10, 2003, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    216
    g.fiorentini
    Sep 10, 2003
  5. Peter Fitzgibbons

    XML Validation against XMLSchema ?

    Peter Fitzgibbons, Oct 17, 2005, in forum: Ruby
    Replies:
    1
    Views:
    132
    Robert Klemme
    Oct 17, 2005
Loading...

Share This Page