我想使用http://www.xmlvalidation.com/来验证xml和dtd,但在处理dtd时遇到错误。我为dtd添加,但它不起作用。我想知道什么是失踪的。我将这两个文件复制并粘贴到一个页面上(没有使用外部)。 谢谢!
<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)>
答案 0 :(得分: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)。