The problem is XML namespaces.
In your XSD, you define targetNamespace= and xmlns= as "http://www.w3schools.com" :
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.w3schools.com" xmlns="http://www.w3schools.com" elementFormDefault="qualified">
However, your XML document does not contain XML namespaces.
<?xml version="1.0"?> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>
Basically, XSD does not validate this XML at all .
You need to either remove these namespaces from your XSD:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
or, conversely, add the default XML namespace (no prefix) defined in XSD to XML:
<?xml version="1.0"?> <note xmlns="http://www.w3schools.com"> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>
If you have XML namespaces in XSD, they must also be present in XML - and vice versa.
As soon as you make one or the other decision, you should get a validation error, for example:
Validation error: The 'body' element is invalid - The value 'Don't forget me this weekend!' is invalid according to its datatype 'http://www.w3.org/2001/XMLSchema:int' - The string 'Don't forget me this weekend!' is not a valid Int32 value.
source share