views:

86

answers:

1

I'm trying to create an XML Schema and I'm stuck. It seems I can't define an element with string content. What am I doing wrong?

Schema:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://ponderka.wz.cz/MusicLibrary0" targetNamespace="http://ponderka.wz.cz/MusicLibrary0"&gt;
    <xs:element name="music-library">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="artist" type="xs:string"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

Document:

<?xml version="1.0"?>
<music-library xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://ponderka.wz.cz/MusicLibrary0 data0.xsd" xmlns="http://ponderka.wz.cz/MusicLibrary0"&gt;
    <artist>a</artist>
</music-library>

The validator says:

Element <artist> is not allowed under element <music-library>.
    Reason: The following elements are expected at this location (see below)
        <artist>
    Error location: music-library / artist
    Details
        cvc-model-group: Element <artist> unexpected by type '{anonymous}' of element <music-library>.
        cvc-elt.5.2.1: The element <music-library> is not valid with respect to the actual type definition '{anonymous}'.
+2  A: 

You are missing this:

attributeFormDefault="unqualified"

Try this:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://ponderka.wz.cz/MusicLibrary0" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
  <xs:element name="music-library">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="artist" type="xs:string" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>
J Angwenyi
It's the `elementFormDefault` attribute, thanks.
svick