【发布时间】:2014-08-05 11:57:21
【问题描述】:
几周以来,我一直在处理这项任务时遇到问题。每次我更改某些内容以解决问题时,都会弹出另一个问题。任何帮助,将不胜感激。在我的 DTD 文档中,我得到了错误:
文档中根元素之前的标记必须格式正确。
在我的 XML 文档中,我得到:
元素类型“viewer_rating”的声明中需要元素类型。
但是,我相信这两个错误都来自我的 DTD 文档。任何帮助将不胜感激。
DTD:
<?xml version="1.0" encoding="UTF-8"?>
<!-- New document created with EditiX at Sun Jul 06 07:25:48 AST 2014 -->
<!ELEMENT movies (movie*)>
<!ELEMENT movie (title, genre, movie_rating, viewer_rating, summary, year, director+, runtime, studio, actors+)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT genre (#PCDATA|action|comedy|drama|family|foreign|horror|musical|other)*>
<!ELEMENT movie_rating (#PCDATA|G|PG|PG-13|R|NC-17)*>
<!ELEMENT viewer_rating (#PCDATA|0 | 1 | 2 | 3 | 4 | 5)*>
<!ELEMENT summary (#PCDATA)>
<!ELEMENT year (#PCDATA)>
<!ELEMENT director (#PCDATA)>
<!ELEMENT runtime (#PCDATA)>
<!ELEMENT studio (#PCDATA)>
<!ELEMENT actors (#PCDATA)>
<!ATTLIST actors id CDATA #REQUIRED>
XML:
<?xml version="1.0" encoding="UTF-8"?>
<!-- New document created with EditiX at Sun Jul 13 10:41:29 AST 2014 -->
<!DOCTYPE movies SYSTEM "MoviesDTD.dtd">
<movies>
<movie>
<title>Transcendence</title>
<genre>Action</genre>
<movie_rating>PG-13</movie_rating>
<viewer_rating>4</viewer_rating>
<summary>In Transcendence, Dr. Will Carter is an expert in Artificial Intelligence, and initially is excited by the promises it offers the world at large. Unfortunately, when he is diagnosed with a terminal disease, his motives change and he becomes focused on his own transcendence. Now he is racing against his own mortality as extremists attempt to stop him. Max Waters is his best friend and a researcher as well, and is torn between helping his friend and what that will mean for society at large.</summary>
<year>2014</year>
<director>Wall Pfistery</director>
<runtime>119</runtime>
<studio>Warner Bros.</studio>
<actors id="1000">Johnny Depp</actors>
<actors id="1001">Paul Bettany</actors>
<actors id="1002">Rebecca Hall</actors>
</movie>
</movies>
再次提前感谢您的帮助。
【问题讨论】:
-
尝试删除顶部的
<!-- New document created with EditiX at Sun Jul 13 10:41:29 AST 2014 -->评论。 -
我创建了一个新的 DTD 类型并复制并粘贴了我的代码,但我仍然收到:元素类型“viewer_rating”的声明中需要元素类型。
-
我建议在这个 XML 中只放一个
以减少人们需要查看的代码量并缩小问题范围。