好的,所以我需要爲XML項目聲明名稱空間,並使用DTD進行驗證。一切似乎都是正確的,即使我的朋友和教授也這樣說,但我不斷收到一條錯誤消息,說「元素」st:course「的前綴」st「沒有綁定。」它看起來受我的約束,我錯過了什麼?XML DTD命名空間沒有綁定
XML:
<?xml-namespace ns="http://www.student_courses/data/st/ns" prefix="st"?>
<?xml-namespace ns="http://www.student_courses/data/cr/ns" prefix="cr"?>
<!DOCTYPE students SYSTEM "student_courses.dtd">
<students>
<student number="a101"> <!-- number is an ID, required-->
<Name title="Mr.">John Doe</Name><!-- title values can be 'Mr.','Ms.','Dr.'-->
<st:course xmlns= "http://www.student_courses/data/st/ns" section="01">WEB 225</st:course>
<enrolled>22</enrolled>
<content>
<level class="Intro"></level>
<comments>Great course</comments><!-- An optional element -->
<book isbn="">XML</book><!--isbn is required, but the element is optional -->
</content>
</student>
<student number="a102"><!-- number is an ID, required-->
<Name title="Dr.">Jane Williams</Name>
<st:course xmlns= "http://www.student_courses/data/st/ns">WEB 325</st:course>
<enrolled>22</enrolled>
<content>
<level class="Adv."></level>
</content>
</student>
<student number="a103"><!-- number is an ID, required-->
<Name title="Ms.">Jane Doe</Name><!-- title values can be 'Mr.','Ms.','Dr.'-->
<st:course xmlns= "http://www.student_courses/data/st/ns" section="03">WEB 440</st:course>
<enrolled>12</enrolled>
<content>
<level class="Adv."></level>
<comments>Great course</comments><!-- An optional element -->
</content>
</student>
<courses>
<cr:course xmlns = "http://www.student_courses/data/cr/ns" id="WEB225">
<name>Web Development II</name>
<offered>Spring</offered>
<pre_reqs>WEB125</pre_reqs>
</cr:course>
<cr:course xmlns = "http://www.student_courses/data/cr/ns" id="WEB125">
<name>Web Development I</name>
<offered>Fall</offered>
</cr:course>
<cr:course xmlns = "http://www.student_courses/data/cr/ns" id="WEB325">
<name>Client-Side Scripting</name>
<offered>Spring</offered>
<offered>Fall</offered>
<pre_reqs>WEB225</pre_reqs>
</cr:course>
</courses>
</students>
這裏是我DTD:
<!ELEMENT students (student+)>
<!ELEMENT student (Name+,st:course+,enrolled+,content+)>
<!ATTLIST student number ID #REQUIRED>
<!ELEMENT Name (#PCDATA)>
<!ATTLIST Name title (Mr. | Ms. | Dr.) #IMPLIED>
<!ELEMENT st:course (#PCDATA)>
<!ATTLIST st:course xmlns CDATA #FIXED "http://www.student_courses/data/st/ns">
<!ATTLIST st:course section CDATA #IMPLIED>
<!ELEMENT enrolled (#PCDATA)>
<!ELEMENT content (level+, comments*, book?)>
<!ELEMENT level (#PCDATA)>
<!ATTLIST level class (Intro | Adv.) #IMPLIED>
<!ELEMENT comments (#PCDATA)>
<!ELEMENT book (#PCDATA)>
<!ATTLIST book isbn CDATA #REQUIRED>
<!ELEMENT courses (cr:course+)>
<!ELEMENT cr:course (name+,offered+,pre_reqs*)>
<!ATTLIST cr:course xmlns:cr CDATA #FIXED "http://www.student_courses/data/cr/ns">
<!ATTLIST cr:course id CDATA #REQUIRED>
<!ELEMENT name (#PCDATA)>
<!ELEMENT offered (#PCDATA)>
<!ELEMENT pre_reqs (#PCDATA)>
謝謝大家,愛這個地方!
-K
請注意,我沒有在官方w3c規範的任何地方找到'xml-namespace'處理指令。 – IllidanS4 2014-05-17 20:42:59