I have an XML that is associated with some XSD. I have included all of the elements in the XML inside the XSD, including Root element. While validating the XML from this XSD, it’s saying that CAS (which’s the root element) is missing.
Anybody have an idea on how to solve this problem?
XML:
<?xml version="1.0"?>
<CAS xmlns="http://www.w3schools.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="CASNamespace ..\..\CAS_backup.xsd">
<name>CAS SD</name>
<casBaseURL>www.sws.bfh.ch/studium/vorlesungen/</casBaseURL>
<course id="C-jav">
<name>Java</name>
<teacher ref="T-joh"/>
<lessons>40</lessons>
<language>de</language>
<language>en</language>
<url>sd-java.xhtml</url>
<weight>1.8</weight>
</course>
<course id="C-xml">
<name>XML Technologien</name>
<teacher ref="T-exe"/>
<lessons>24</lessons>
<project>8</project>
<language>de</language>
<language>en</language>
<url>sd-xml.xhtml</url>
<weight>1.6</weight>
</course>
<course id="C-rdb">
<name>Relationale Datenbanken</name>
<teacher ref="T-bas"/>
<lessons>24</lessons>
<project>8</project>
<language>de</language>
<language>en</language>
<language>fr</language>
<url>sd-rdb.xhtml</url>
<weight>1.6</weight>
</course>
<course id="C-da">
<name>Datenstrukturen und Algorithmen</name>
<teacher ref="T-rit"/>
<lessons>48</lessons>
<language>de</language>
<language>en</language>
<url>sd-algodata.xhtml</url>
<weight>1.8</weight>
</course>
<course id="C-gui">
<name>GUI/Ergonomie</name>
<teacher ref="T-joh"/>
<teacher ref="T-nom"/>
<lessons>24</lessons>
<project>16</project>
<language>de</language>
<language>en</language>
<url>sd-gui.xhtml</url>
<weight>1.6</weight>
</course>
<student id="P-001">
<name>
<firstName>Roberto</firstName>
<lastName>Campione</lastName>
</name>
<dateOfBirth>1970-12-12</dateOfBirth>
<address>
<street>
<name>Bahnhofstrasse</name>
<number>12</number>
<addition>a</addition>
</street>
<postalCode>4000</postalCode>
<city>Basel</city>
<country>Schweiz</country>
</address>
<ratings>
<rating ref="C-xml"><grade>85</grade></rating>
<rating ref="C-da"><grade>82</grade></rating>
</ratings>
</student>
<student id="P-002">
<name>
<firstName>Willis</firstName>
<middleName>R.</middleName>
<lastName>Pattern</lastName>
</name>
<dateOfBirth>1975-10-12</dateOfBirth>
<address>
<street>
<name>Hauptstrasse</name>
<number>10</number>
</street>
<postalCode>6000</postalCode>
<city>Luzern</city>
<country>Schweiz</country>
</address>
<ratings>
<rating ref="C-da"><grade>45</grade></rating>
<rating ref="C-xml"><grade>75</grade></rating>
<rating ref="C-jav"><grade>75</grade></rating>
</ratings>
</student>
<student id="P-003">
<name>
<firstName>Anna</firstName>
<middleName>Maria</middleName>
<lastName>Muster</lastName>
</name>
<dateOfBirth>1978-10-29</dateOfBirth>
<address>
<street>
<name>Langstrasse</name>
<number>8</number>
</street>
<postalCode>3000</postalCode>
<city>Bern</city>
<country>Schweiz</country>
</address>
<ratings>
<rating ref="C-da"><grade>75</grade></rating>
<rating ref="C-rdb"><grade>96</grade></rating>
<rating ref="C-jav"><grade>88</grade></rating>
<rating ref="C-gui"><grade>78</grade></rating>
</ratings>
</student>
<student id="P-004">
<name>
<firstName>Hans</firstName>
<middleName>Jochen</middleName>
<lastName>Musterhans</lastName>
</name>
<dateOfBirth>1980-08-12</dateOfBirth>
<address>
<street>
<name>Langgasse</name>
<number>4</number>
</street>
<postalCode>8000</postalCode>
<city>Winterthur</city>
<country>Schweiz</country>
</address>
<ratings>
<rating ref="C-da"><grade>95</grade></rating>
<rating ref="C-rdb"><grade>92</grade></rating>
<rating ref="C-jav"><grade>78</grade></rating>
<rating ref="C-xml"><grade>76</grade></rating>
<rating ref="C-gui"><grade>88</grade></rating>
</ratings>
</student>
<student id="P-005">
<name>
<firstName>Christina</firstName>
<lastName>Muster</lastName>
</name>
<dateOfBirth>1968-04-22</dateOfBirth>
<address>
</CAS>
XSD:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="NewDataSet" xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="CASNamespace" xmlns="CASNamespace" xmlns:msdata="urn:schemas- microsoft-com:xml-msdata">
<xs:element name="CAS" type="CASType"/>
<xs:complexType name="CASType">
<xs:sequence>
<xs:element ref="name"/>
<!--<xs:element ref="casBaseURL"/>-->
<xs:element maxOccurs="unbounded" ref="course"/>
<xs:element maxOccurs="unbounded" ref="student"/>
<xs:element maxOccurs="unbounded" ref="teacher"/>
<!--<xs:element ref="courseParticipants"/>-->
</xs:sequence>
</xs:complexType>
<xs:element name="course">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string" minOccurs="0"/>
<xs:element name="lessons" type="xs:string" minOccurs="1" maxOccurs="50" />
<xs:element name="project" type="xs:string" minOccurs="0"/>
<xs:element name="url" minOccurs="1" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-zA-Z].*.xhtml"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="weight" minOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:float">
<xs:pattern value="[0-9]\.[0-9]"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element ref="teacher" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="language" nillable="false" minOccurs="1" maxOccurs="4">
<xs:complexType>
<xs:simpleContent msdata:ColumnName="language_Text" msdata:Ordinal="0">
<xs:extension base="xs:string" />
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element ref="student" minOccurs="1" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="id">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[C]-[a-z][A-Z].*"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="ref" type="xs:string" />
</xs:complexType>
</xs:element>
<xs:element name="teacher">
<xs:complexType>
<xs:sequence>
<xs:element ref="name" minOccurs="1" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="ref" type="xs:string" />
<xs:attribute name="id">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[T]-[a-z][A-Z].*"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="student">
<xs:complexType>
<xs:sequence>
<xs:element name="dateOfBirth" minOccurs="1" maxOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="Year">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="1920"/>
<xs:maxInclusive value="2000"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Month">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="1"/>
<xs:maxInclusive value="12"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Day">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="1"/>
<xs:maxInclusive value="31"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element ref="name" minOccurs="1" maxOccurs="unbounded" />
<xs:element name="address" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="postalCode" minOccurs="4" maxOccurs="5">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[0-9].*"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="city" type="xs:string" minOccurs="0" />
<xs:element name="country" type="xs:string" minOccurs="0" />
<xs:element name="street" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="name" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-zA-Z].*"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="number" minOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[0-9].*"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="addition" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="ratings" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="rating" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="grade" minOccurs="1" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="1"/>
<xs:maxInclusive value="100"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
<xs:attribute name="ref" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="id">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[P]-[a-z][A-Z].*"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="ref" type="xs:string" />
</xs:complexType>
</xs:element>
<xs:element name="name">
<xs:complexType>
<xs:sequence>
<xs:element name="firstName" minOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-z].*"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="middleName" minOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-z].*"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="lastName" minOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-z].*"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Regards,
Usman
Your Xml document specifies
xmlns="http://www.w3schools.com"as its default namespace whereas your schema specifiestargetNamespace="CASNamespace" xmlns="CASNamespace"as the target namespace.Change
xmlns="http://www.w3schools.com"in your Xml document toxmlns="CASNamespace"and your document will … still not validate because it complains that it expects element<course/>instead of<casBaseURL />.