2016-11-09 65 views
2

我想用http://www.xmlvalidation.com/驗證XML和DTD DTD,但在處理DTD了錯誤。我添加了dtd,但它不起作用。我不知道缺少什麼。我將這兩個文件複製並粘貼到一個頁面上(沒有使用外部)。 謝謝!如何驗證XML和在線資源

<Bookstore> 
<Book ISBN = "ISBN-101" Price = "100" Authors = "JU JW"> 
    <Title> 
     Introduction to Python 
    </Title>  
</Book> 
<Book ISBN = "ISBN-202" Price = "120" Authors = "HG JU JW"> 
    <Title> 
     Digital Circuit Design 
    </Title> 
    <Remark> 
     Amazon.com says: Buy this book bundled with 
     <BookRef book = "ISBN-303" /> - a great deal! 
    </Remark>  
</Book> 

<Author Ident = "HG"> 
    <Firstname>Hector</Firstname> 
    <Lastname>Garcia</Lastname> 
</Author> 
<Author Ident = "JU"> 
    <Firstname>Jeffrey</Firstname> 
    <Lastname>Ullman</Lastname> 
</Author> 
<Author Ident = "JW"> 
    <Firstname>Jennifer</Firstname> 
    <Lastname>Widom</Lastname> 
</Author> 

<!ELEMENT Bookstore(Book*, Author*)> 
<!ELEMENT Book (Title, Remark?)> 
<!ATTLIST Book ISBN ID #REQUIRED 
      Price CDATA #REQUIRED 
      Authors IDREFS #REQUIRED> 

<!ELEMENT Title(#PCDATA)> 
<!ELEMENT Remark(#PCDATA | BookRef)*> 
<!ELEMENT BookRef EMPTY> 
<!ATTLIST BokkRef book IDREF #REQUIRED> 
<!ELEMENT Author(Firstname,Lastname)> 
<!ATTLIST Author Ident ID #REQUIRED> 
<!ELEMENT Firstname(#PCDATA)> 
<!ELEMENT Lastname(#PCDATA)> 

回答

1

如果你想在DTD和XML實例相結合,添加一個DOCTYPE聲明,並把DTD聲明的內部子集(增加一個prolog)...

<!DOCTYPE Bookstore [ 
<!ELEMENT Bookstore (Book*, Author*)> 
<!ELEMENT Book (Title, Remark?)> 
<!ATTLIST Book ISBN ID #REQUIRED 
      Price CDATA #REQUIRED 
      Authors IDREFS #REQUIRED> 

<!ELEMENT Title (#PCDATA)> 
<!ELEMENT Remark (#PCDATA | BookRef)*> 
<!ELEMENT BookRef EMPTY> 
<!ATTLIST BookRef book IDREF #REQUIRED> 
<!ELEMENT Author (Firstname,Lastname)> 
<!ATTLIST Author Ident ID #REQUIRED> 
<!ELEMENT Firstname (#PCDATA)> 
<!ELEMENT Lastname (#PCDATA)> 
]> 
<Bookstore> 
    <Book ISBN="ISBN-101" Price="100" Authors="JU JW"> 
     <Title> 
      Introduction to Python 
     </Title>  
    </Book> 
    <Book ISBN="ISBN-202" Price="120" Authors="HG JU JW"> 
     <Title> 
      Digital Circuit Design 
     </Title> 
     <Remark> 
      Amazon.com says: Buy this book bundled with 
      <BookRef book="ISBN-303"/> - a great deal! 
     </Remark>  
    </Book> 

    <Author Ident="HG"> 
     <Firstname>Hector</Firstname> 
     <Lastname>Garcia</Lastname> 
    </Author> 
    <Author Ident="JU"> 
     <Firstname>Jeffrey</Firstname> 
     <Lastname>Ullman</Lastname> 
    </Author> 
    <Author Ident="JW"> 
     <Firstname>Jennifer</Firstname> 
     <Lastname>Widom</Lastname> 
    </Author> 
</Bookstore> 

我固定在DTD聲明的一些錯字,但文件仍然有一個無效的IDREF的問題(缺少相應的ID)。