簡體   English   中英

使用 XSD 驗證的“找不到元素聲明”

[英]"Cannot find the declaration of element" validating with XSD

我是 XML 的完全初學者,我正在嘗試學習 XML 模式。 我有這兩個文件:

備注.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>

筆記.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>

在 note.xml 我收到錯誤

cvc-elt.1.a:找不到元素“note”.xml 的聲明

在我的根音符元素上。 我在這里看過其他帖子,但對於更復雜的解決方案,但我是一個完整的初學者,什么都不明白。 如果您能指導我解決此錯誤,我將不勝感激。

改變

xsi:schemaLocation="https://www.w3schools.com/xml note.xsd"

xsi:schemaLocation="https://www.w3schools.com note.xsd"

以便命名空間 URL 與 XML 文檔中的xmlns="https://www.w3schools.com"和 XSD 中的targetNamespace="https://www.w3schools.com"相匹配。

也可以看看

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM