You made two errors: one in the schema file and another in the syntax of the value of the xsi:schemaLocation
attribute of the XML file.
The main error is that your employee.xsd file is only a fragment of the XML Schema. You should complete the contain of the employee.xsd. For example,
<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="http://www.w3schools.com/RedsDevils"
elementFormDefault="qualified"
xmlns="http://www.w3schools.com/RedsDevils employee.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="employee">
<xs:complexType>
<xs:sequence>
<xs:element name="firstname" type="xs:string" fixed="red" />
<xs:element name="lastname" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
and employee.xml:
<?xml version="1.0" encoding="utf-8"?>
<employee xmlns="http://www.w3schools.com/RedsDevils"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3schools.com/RedsDevils employee.xsd">
<firstname>John</firstname>
<lastname>Smith</lastname>
</employee>
Because you define default namespace in the XML file, the schema location attribule xsi:schemaLocation
must consist from the the namespace and the path to the schema devided with the blank. I changed the namespace name so that it will be a little more unique: "http://www.w3schools.com/RedsDevils"
instead of "http://www.w3schools.com"
.
At the end I can add that the XML file employee.xml not corresponds to the schema employee.xsd because the element <firstname>John</firstname>
has the value other as red
, but probably exactly this you wanted to test.