元素类型“viewer_rating”错误的声明中需要'('字符或元素类型

时间:2014-07-13 23:10:21

标签: xml xml-dtd

我在DTD代码中不断收到此错误。我试过添加")"和其他角色似乎没什么用。

<?xml version="1.0" encoding="UTF-8"?>

<!-- New document created with EditiX at Sun Jul 13 10:48:54 AST 2014 -->

<!DOCTYPE movies
[
<!ELEMENT movies-movie (movies-movie*)>  
<!ELEMENT movie (title, genre, movie_rating, viewer_rating, summary, year, director+, runtime, studio, actors+)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT genre (action|comedy|drama|family|foreign|horror|musical|other)>
<!ELEMENT movie_rating (G|PG|PG-13|R|NC-17)>
<!ELEMENT viewer_rating ( | 1 | 2 | 3 | 4 | 5)><!--receive error here -->

<!ELEMENT summary (#PCDATA)>
<!ELEMENT year (#PCDATA)>
<!ELEMENT director (#PCDATA)>
<!ELEMENT runtime (#PCDATA)>
<!ELEMENT studio (#PCDATA)>
<!ELEMENT actors (#PCDATA)>
<!ATTLIST actors id CDATA #REQUIRED>
]>

任何帮助将不胜感激 谢谢

1 个答案:

答案 0 :(得分:1)

您已尝试在元素上使用枚举。我非常确定枚举仅限于属性。试试这个:

<!ELEMENT movies (movie*)>  
<!ELEMENT movie (title, summary, year, director+, runtime, studio, actors+)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT summary (#PCDATA)>
<!ELEMENT year (#PCDATA)>
<!ELEMENT director (#PCDATA)>
<!ELEMENT runtime (#PCDATA)>
<!ELEMENT studio (#PCDATA)>
<!ELEMENT actors (#PCDATA)>
<!ATTLIST movie genre (action|comedy|drama|family|foreign|horror|musical|other) #REQUIRED>
<!ATTLIST movie movie_rating (G|PG|PG-13|R|NC-17)  #REQUIRED>
<!ATTLIST movie viewer_rating (0 | 1 | 2 | 3 | 4 | 5) #REQUIRED>
<!ATTLIST actors id CDATA #REQUIRED>

这使得电影的类型,电影评级和观众评级属性而不是元素。

观众评分中还有一个空标记:( | 1|...是不允许的。您可以将其更改为#IMPLIED并在没有收视率的情况下将其保留,或者使用像&#34; 0&#34;正如我所做的那样,表示没有评级。

如果电影评级和流派是可选的,请将#REQUIRED更改为#IMPLIED。

您放置<!DOCTYPE...的位置取决于这是内部还是外部DTD。