1

I'm a complete beginner in XML, and I'm trying to learn XML Schema. I have these two files:

note.xml

<?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>

note.xsd

<?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.

kjhughes
  • 106,133
  • 27
  • 181
  • 240
vasilis 123
  • 585
  • 1
  • 12
  • 26

1 Answers1

0

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.

See also

kjhughes
  • 106,133
  • 27
  • 181
  • 240