簡體   English   中英

為什么我的XML文件沒有驗證,但格式正確?

[英]Why is my XML file not validating, but is well-formed?

我對XML極為陌生,在過去的3天里,我一直在關注這個簡單的文件。 就我現在而言,我聲明的每個元素和屬性都是正確的,我按照教科書進行了兩次重新閱讀和重新分配,但始終出現此錯誤。 我缺少什么,如何糾正錯誤並最終提交作業(后期)?

盡管這本書說得很准確,但我仍然會遇到以下錯誤:

[Xerces-J 2.9.1] Validating "mdpba1.xml" against "Internal DocType Declaration" ...

Ln 33列47-必須為元素類型“帶”聲明屬性“名稱”。 1個錯誤

這是我的代碼:

 <?xml version="1.0" encoding="UTF-8" standalone="no" ?> <!-- New Perspectives on XML Tutorial 2 Case Problem 2 Filename: mdpba.xml --> <!DOCTYPE bands [ <!ENTITY celtic SYSTEM "celtic.jpg" NDATA JPG> <!ENTITY badger SYSTEM "badger.jpg" NDATA JPG> <!ELEMENT bands (band+)> <!ELEMENT band (name, city, logo?, competition)> <!ATTLIST band cid ID #REQUIRED> <!ELEMENT name (#PCDATA)> <!ATTLIST name grade (1 | 2 | 3 | 4 | 5 | juvenile | novice) #REQUIRED> <!ELEMENT city (#PCDATA)> <!ELEMENT logo EMPTY> <!ATTLIST logo source ENTITY #REQUIRED> <!ELEMENT competition (event, event)> <!ELEMENT event (tune+)> <!ATTLIST event type (MSR | Medley) #REQUIRED> <!ELEMENT tune (#PCDATA)> <!NOTATION JPG SYSTEM "image/jpg"> ]> <bands name="Midwest Developmental Pipe Band"> <band cid="c0001"> <name grade="juvenile">School of Celtic Bagpipes &amp; Drumming</name> <city>Delafield</city> <logo source="celtic" /> <competition> <event type="MSR"> <tune>Charlies Welcome</tune> <tune>Mrs MacPherson of Inveran</tune> <tune>Brown Haired Maiden</tune> </event> <event type="Medley"> <tune>Rowd's Hornpipe</tune> </event> </competition> </band> <band cid="c0002"> <name grade="juvenile">Badger Pipes and Drums</name> <city>Madison</city> <logo source="badger" /> <competition> <event type="MSR"> <tune>Lord Alexander Kennedy</tune> <tune>Bob of Fettercairn</tune> <tune>Brown Haired Maiden</tune> </event> <event type="Medley"> <tune>Out of the Air</tune> </event> </competition> </band> <band cid="c0003"> <name grade="novice">Pardeeville School of Piping and Drumming</name> <city>Pardeeville</city> <competition> <event type="MSR"> <tune>Lord Alexander Kennedy</tune> <tune>Bob of Fettercairn</tune> <tune>The Little Cascade</tune> </event> <event type="Medley"> <tune>The Radar Racketeer</tune> </event> </competition> </band> <band cid="c0004"> <name grade="3">Zoar Scottish Pipe Band</name> <city>Zoar</city> <competition> <event type="MSR"> <tune>Charlies Welcome</tune> <tune>Mrs MacPherson of Inveran</tune> <tune>Major Manson</tune> </event> <event type="Medley"> <tune>Miss Lily</tune> </event> </competition> </band> <band cid="c0005"> <name grade="juvenile">Stockholm Pipe Band</name> <city>Stockholm</city> <competition> <event type="MSR"> <tune>Pretty Marion</tune> <tune>The Sheepwife</tune> <tune>Brown Haired Maiden</tune> </event> <event type="Medley"> <tune>Farewell to Erin</tune> </event> </competition> </band> </bands>​ 

我缺乏經驗,因此不確定如何解決問題而不弄亂任何東西,將非常感謝您的幫助,謝謝...

您的問題是因為XML標頭中的DTD規范未將name指定為元素<bands>的有效或預期屬性

如果將此屬性所需的DTD定義添加到XML,它將進行驗證。

<!ATTLIST bands name CDATA #REQUIRED>

這是您更正的XML:

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<!--
   New Perspectives on XML
   Tutorial 2
   Case Problem 2

   Filename:         mdpba.xml 
-->
<!DOCTYPE bands [

<!ENTITY celtic SYSTEM "celtic.jpg" NDATA JPG>
<!ENTITY badger SYSTEM "badger.jpg" NDATA JPG>

<!ELEMENT bands (band+)>
<!ATTLIST bands name CDATA #REQUIRED>
<!ELEMENT band (name, city, logo?, competition)>
<!ATTLIST band cid ID #REQUIRED>
<!ELEMENT name (#PCDATA)>
<!ATTLIST name grade (1 | 2 | 3 | 4 | 5 | juvenile | novice) #REQUIRED>
<!ELEMENT city (#PCDATA)>
<!ELEMENT logo EMPTY>
<!ATTLIST logo source ENTITY #REQUIRED>
<!ELEMENT competition (event, event)>
<!ELEMENT event (tune+)>
<!ATTLIST event type (MSR | Medley) #REQUIRED>
<!ELEMENT tune (#PCDATA)>
<!NOTATION JPG SYSTEM "image/jpg">

]>
<bands name="Midwest Developmental Pipe Band">
   <band cid="c0001">
      <name grade="juvenile">School of Celtic Bagpipes &amp; Drumming</name>
      <city>Delafield</city>
      <logo source="celtic" />
      <competition>
         <event type="MSR">
            <tune>Charlies Welcome</tune>
            <tune>Mrs MacPherson of Inveran</tune>
            <tune>Brown Haired Maiden</tune>
         </event>
         <event type="Medley">
            <tune>Rowd's Hornpipe</tune>
         </event>
      </competition>
   </band>
   <band cid="c0002">
      <name grade="juvenile">Badger Pipes and Drums</name>
      <city>Madison</city>
      <logo source="badger" />
      <competition>
         <event type="MSR">
            <tune>Lord Alexander Kennedy</tune>
            <tune>Bob of Fettercairn</tune>
            <tune>Brown Haired Maiden</tune>
         </event>
         <event type="Medley">
            <tune>Out of the Air</tune>
         </event>
      </competition>
   </band>
   <band cid="c0003">
      <name grade="novice">Pardeeville School of Piping and Drumming</name>
      <city>Pardeeville</city>
      <competition>
         <event type="MSR">
            <tune>Lord Alexander Kennedy</tune>
            <tune>Bob of Fettercairn</tune>
            <tune>The Little Cascade</tune>
         </event>
         <event type="Medley">
            <tune>The Radar Racketeer</tune>
         </event>
      </competition>
   </band>
   <band cid="c0004">
      <name grade="3">Zoar Scottish Pipe Band</name>
      <city>Zoar</city>
      <competition>
         <event type="MSR">
            <tune>Charlies Welcome</tune>
            <tune>Mrs MacPherson of Inveran</tune>
            <tune>Major Manson</tune>
         </event>
         <event type="Medley">
            <tune>Miss Lily</tune>
         </event>
      </competition>
   </band>
   <band cid="c0005">
      <name grade="juvenile">Stockholm Pipe Band</name>
      <city>Stockholm</city>
      <competition>
         <event type="MSR">
            <tune>Pretty Marion</tune>
            <tune>The Sheepwife</tune>
            <tune>Brown Haired Maiden</tune>
         </event>
         <event type="Medley">
            <tune>Farewell to Erin</tune>
          </event>
      </competition>
   </band>
</bands>

暫無
暫無

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

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