嘿伙计们我有一个外部的XML DTD代码但是当我尝试验证它时,我似乎得到了一个错误。我的代码如下:
<!DOCTYPE catalog [
<!ELEMENT catalog (book)+>
<!ELEMENT book (title, authors, year_published, ISBN, number_of_pages, price) >
<!ELEMENT title (#PCDATA)>
<!ELEMENT authors (author)>
<!ELEMENT author (first_name, last_name, gender)>
<!ELEMENT first_name (#PCDATA)>
<!ELEMENT last_name (#PCDATA)>
<!ELEMENT gender (#PCDATA)>
<!ELEMENT year_pusblished (#PCDATA)>
<!ELEMENT ISBN (#PCDATA)>
<!ELEMENT number_of_pages (#PCDATA)>
<!ELEMENT price (discount)>
<!ATTLIST price discount (yes|no) "no">]>
我知道一切都是正确的但是当我验证它时会出现错误消息:
“文档类型声明中包含或指向的标记声明必须格式正确。第3行第4列”
我已经检查了一切,但我似乎无法让它工作。你们能帮忙吗?
答案 0 :(得分:0)
如果你写入文件.xml你没有生成错误,但如果你有.dtd文件,你必须清除该元素! 正确的文件test.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE catalog [
<!ELEMENT catalog (book)+>
<!ELEMENT book (title, authors, year_published, ISBN, number_of_pages, price) >
<!ELEMENT title (#PCDATA)>
<!ELEMENT authors (author)>
<!ELEMENT author (first_name, last_name, gender)>
<!ELEMENT first_name (#PCDATA)>
<!ELEMENT last_name (#PCDATA)>
<!ELEMENT gender (#PCDATA)>
<!ELEMENT year_pusblished (#PCDATA)>
<!ELEMENT ISBN (#PCDATA)>
<!ELEMENT number_of_pages (#PCDATA)>
<!ELEMENT price (discount)>
<!ATTLIST price discount (yes|no) "no">]>
<catalog>
<book>
<title></title>
<authors>
<author>
<first_name></first_name>
<last_name></last_name>
<gender></gender>
</author>
</authors>
<year_published></year_published>
<ISBN></ISBN>
<number_of_pages></number_of_pages>
<price>
<discount></discount>
</price>
</book>
</catalog>
更正文件test.dtd(链接到xml文件,声明到同一个test.xml):
<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT catalog (book)+>
<!ELEMENT book (title, authors, year_published, ISBN, number_of_pages, price) >
<!ELEMENT title (#PCDATA)>
<!ELEMENT authors (author)>
<!ELEMENT author (first_name, last_name, gender)>
<!ELEMENT first_name (#PCDATA)>
<!ELEMENT last_name (#PCDATA)>
<!ELEMENT gender (#PCDATA)>
<!ELEMENT year_pusblished (#PCDATA)>
<!ELEMENT ISBN (#PCDATA)>
<!ELEMENT number_of_pages (#PCDATA)>
<!ELEMENT price (discount)>
<!ATTLIST price discount (yes|no) "no">