DTD到XML错误

时间:2015-11-25 18:09:36

标签: xml xml-parsing

所以我正在设计一个基于某个DTD的XML文件。因此逻辑是:

Category >> Books(can have many entries) >>Author[required], Price[required], Description, Image)

以下是生成的DTD:

<!ELEMENT CATAGORY (PRODUCT+)>
<!ELEMENT PRODUCT
(NAME,PRICE,DESCRIPTION*,PICTURE*)>
<!ATTLIST PRODUCT
NAME CDATA #REQUIRED
PRICE CDATA #REQUIRED
DESCRIPTION CDATA #IMPLIED
PICTURE CDATA #IMPLIED
CATEGORY (BOOKS|GADGETS|OTHERS) "BOOKS"
AUTHOR CDATA #REQUIRED
ISBN CDATA #IMPLIED
INVENTORY (InStock|Backordered|Discontinued) "InStock">

但是,我无法编写有效的XML。我写道:

<CATAGORY>
    <PRODUCT NAME="XML BOOK" AUTHOR="XML GENIUS" CATEGORY="BOOKS" DESCRIPTION="BRILLIANT XML BOOK."  INVENTORY="InStock" ISBN="653725327" PRICE="36.99" PICTURE=""/>
    <PRODUCT NAME="XML MASTERS" AUTHOR="XML TEACHER" CATEGORY="BOOKS" DESCRIPTION="" INVENTORY="InStock" ISBN="" PICTURE="" PRICE="23.99"/> 
</CATAGORY>

我收到以下错误。任何帮助表示赞赏。

Content model of element <PRODUCT> requires further child elements.
    Error location: CATAGORY / PRODUCT
    Details
        VC: Element Valid (2): Content model of element <PRODUCT> requires further child elements.

1 个答案:

答案 0 :(得分:0)

PRODUCT的定义,

<!ELEMENT PRODUCT
    (NAME,PRICE,DESCRIPTION*,PICTURE*)>

说,<PRODUCT>必须包含一个<NAME>元素,一个<PRICE>元素,依此类推。但是从ATTLIST和你想要使用属性的示例代码。所以只需将定义更改为

即可
<!ELEMENT PRODUCT EMPTY>