XML 文件中的内部 DTD 错误

Error on internal DTD in XML File

我的 XML 文件无法 运行。我在 DTD 上遇到了一些错误。我的 DTD 代码有什么问题?我试过 运行 在 Internet Explorer 上打开它,但它不起作用。当我不包括 DTD 代码时,它工作正常。但是一旦我包含了 DTD,它就会显示一个空白页。一旦我验证了 http://validator.w3.org/ 中的 xml 文件,我得到了这些错误

Line 25, Column 23: document type does not allow element "book" here

<book instock = "yes">

The element named above was found in a context where it is not allowed. This could mean that you have incorrectly nested elements -- such as a "style" element in the "body" section instead of inside "head" -- or two elements that overlap (which is not allowed)

One common cause for this error is the use of XHTML syntax in HTML documents. Due to HTML's rules of implicitly closed elements, this error can create cascading effects. For instance, using XHTML's "self-closing" tags for "meta" and "link" in the "head" section of a HTML document may cause the parser to infer the end of the "head" section and the beginning of the "body" section (where "link" and "meta" are not allowed; hence the reported error)

<?xml version = "1.0" encoding="UTF-8" standalone="yes" ?>
<?xml-stylesheet type ="text/css" href="Books.css"?>

<!DOCTYPE inventory [
    <!ELEMENT inventory(book)>
    <!ELEMENT book(title,author,isbn,publisher,pages,price)>
<!ATTLIST book instock CDATA #REQUIRED>
    <!ELEMENT title(#PCDATA)>
    <!ELEMENT author(#PCDATA)>
    <!ELEMENT isbn(#PCDATA)>
    <!ELEMENT publisher(#PCDATA)>
    <!ELEMENT pages(#PCDATA)>
    <!ELEMENT price(#PCDATA)>
]>

<inventory>
    <book instock = "yes">
        <title>Beginning web programming with html, xhtml, and css </title>
        <author>Duckett, jon </author>
        <isbn>0764570781</isbn>
        <publisher>Wrox pr inc</publisher>
        <pages>840</pages>
        <price>MYR 119.80</price>
    </book>
    <book instock = "yes">
        <title>Core web programming(2nd edition)</title>
        <author>Marty hall, larry brown</author>
        <isbn>0130897930 </isbn>
        <publisher>Prentice hall ptr </publisher>
        <pages>1385</pages>
        <price> MYR 125.00</price>
    </book>
    <book instock = "no">
        <title>An introduction to web design and programming</title>
        <author>Paul s. wang, sanda katila</author>
        <isbn>0534395287</isbn>
        <publisher>Course technology</publisher>
        <pages>592</pages>
        <price> MYR 251.00</price>
    </book>
</inventory>
<!ELEMENT inventory(book)>

这表示一个 inventory 元素可以恰好包含一个 book。你想要

<!ELEMENT inventory(book)*>

或者也许

<!ELEMENT inventory(book)+>