I'm a complete beginner in XML, and I'm trying to learn XML Schema. I have these two files:
<?xml version="1.0" encoding="UTF-8"?>
<note
xmlns="https://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://www.w3schools.com/xml note.xsd">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="https://www.w3schools.com"
xmlns = "https://www.w3schools.com"
elementFormDefault="qualified">
<xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name = "to" type ="xs:string"/>
<xs:element name = "from" type = "xs:string"/>
<xs:element name = "heading" type = "xs:string"/>
<xs:element name = "body" type = "xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
In note.xml I get the error
cvc-elt.1.a: Cannot find the declaration of element 'note'.xml
on my root note element. I have seen other posts here but for more complex solutions but I am a complete beginner and don't understand a thing. I would appreciate it if you could guide me through this error.
Change
xsi:schemaLocation="https://www.w3schools.com/xml note.xsd"
to
xsi:schemaLocation="https://www.w3schools.com note.xsd"
so that the namespace URL matches xmlns="https://www.w3schools.com"
in the XML document and targetNamespace="https://www.w3schools.com"
in the XSD.