XML和DTD:如何修复内容元素类型必须匹配/不完整

时间:2019-07-14 20:37:14

标签: xml hyperlink dtd

使用外部DTD表开始学习XML和DTD。尝试将作者的名字链接到网页,我可以使代码正常工作,但是当我验证我的代码时,我很难使某些内容元素匹配/内容元素类型不完整。将其放入xmlvalidation.com,我收到两条错误消息:

  

46:13元素类型“作者”的内容不完整,必须   匹配“(html:a?,firstname,middlename?,lastname)”。

     

52:15内容   类型元素“ titlepage”必须匹配   “((标题|字幕|作者|翻译者|日期|注释)*”。

我尝试过声明html:a元素应该声明的位置,并将html:a放在不同的位置以及我认为应该放置的位置,因此它遵循xml文档中的样子,但是这似乎给我带来了更多问题。

XML文件:

<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="KB-SciFi.v02.css"?>
<!DOCTYPE book SYSTEM "book.v02.dtd">

<book xmlns="http://www.kwongbor.net/KBCollectionNames/"
      xmlns:html="http://www.w3.org/1999/xhtml"> 
  <metadata xmlns:dc="http://purl.org/dc/elements/1.1/">
    <dc:title>The Time Machine</dc:title>
    <dc:creator>Wells, H. G. (Herbert George), 1866-1946 </dc:creator>
    <dc:subject>Science fiction</dc:subject>
    <dc:subject>PR</dc:subject>
    <dc:language>eng</dc:language>
    <dc:description> </dc:description>
    <dc:publisher> www.kwongbor.net</dc:publisher>
    <dc:date>2007-10-15</dc:date>
    <dc:type>World Wide Web resource</dc:type>
    <dc:type>electronic resource</dc:type>
    <dc:type>text/xml</dc:type>
    <dc:identifier>http://www.kwongbor.net/eCollection/DTD/WellsHG-TimeMachine.v01.xml</dc:identifier>
    <dc:source> </dc:source>
    <dc:relation>K.B.Ng's GSLIS 729</dc:relation>
    <dc:relation>Browser with XML parser</dc:relation>
    <dc:relation>Mode of access: Internet via World Wide Web</dc:relation>
    <dc:coverage> </dc:coverage>
    <dc:rights>The only legal and authorized use of these files is for the nonprofit production. 
    The copyright for these files is the sole property of the original owner.  </dc:rights>
    <dc:rights>Access limited to students of GSLIS 729.
    </dc:rights>
  </metadata>

  <frontmatter>
    <html:img 
        src="timemachinebookcover.jpg" 
    style="float: left;"/>
    <titlepage>
      <title> The Time Machine </title> 
      <author>
    <html:a href="http://en.wikipedia.org/wiki/H._G._Wells" target="_blank">
      <firstname> Herbert </firstname>      
      <middlename> George </middlename>
      `<lastname> Wells </lastname>
    </html:a>
      </author>
      <html:img 
      src="HGWells1922.small.gif"  
      style="margin-left: 20px;"/>

      <date> 1895 </date>
    </titlepage>
  </frontmatter>
  <body></body>
  <end></end>
</book>

DTD文件:

<!ENTITY % pname "((html:a)?, firstname, middlename?, lastname)">
<!ELEMENT html:a (firstname, middlename, lastname)*>
<!ATTLIST html:a 
        href CDATA #IMPLIED
        target CDATA #IMPLIED>
<!ELEMENT firstname (#PCDATA)>
<!ELEMENT middlename (#PCDATA)>
<!ELEMENT lastname (#PCDATA)>

<!ELEMENT html:img  EMPTY>
<!ATTLIST html:img 
        src CDATA #IMPLIED
        style CDATA #IMPLIED>

<!ENTITY % frontmatter "(html:img?, titlepage*, tableofcontents?, listoffigures?, preface*, foreword*, dedication*, acknowledgment*, errata*, frontispiece*)">

<!ENTITY % titleinfo "(title | subtitle | author | translator | date | note)*">
<!ELEMENT title (#PCDATA) >
<!ELEMENT date (#PCDATA) >

<!ELEMENT author %pname;>

<!ELEMENT book (metadata, frontmatter, body, end)>
<!ATTLIST book 
    xmlns CDATA #FIXED "http://www.kwongbor.net/KBCollectionNames/"
    xmlns:html CDATA #FIXED "http://www.w3.org/1999/xhtml"> 

<!ELEMENT metadata (dc:title | dc:creator | dc:subject | dc:description | dc:publisher | dc:contributor | dc:date | dc:type | dc:format | dc:identifier | dc:source | dc:language | dc:relation | dc:coverage | dc:rights)*>
<!ATTLIST metadata xmlns:dc CDATA #FIXED "http://purl.org/dc/elements/1.1/"> 
<!ELEMENT dc:title (#PCDATA) >
<!ELEMENT dc:creator (#PCDATA) >
<!ELEMENT dc:subject (#PCDATA) >
<!ELEMENT dc:description (#PCDATA) >
<!ELEMENT dc:publisher (#PCDATA) >
<!ELEMENT dc:contributor (#PCDATA) >
<!ELEMENT dc:date (#PCDATA) >
<!ELEMENT dc:type (#PCDATA) >
<!ELEMENT dc:format (#PCDATA) >
<!ELEMENT dc:identifier (#PCDATA) >
<!ELEMENT dc:source (#PCDATA) >
<!ELEMENT dc:language (#PCDATA) >
<!ELEMENT dc:relation (#PCDATA) >
<!ELEMENT dc:coverage (#PCDATA) >
<!ELEMENT dc:rights (#PCDATA) >

<!ELEMENT frontmatter (%frontmatter;)>
<!ELEMENT titlepage %titleinfo;>

<!ELEMENT body (part | chapter | subchapter | paragraph | poem | note)* >
<!ELEMENT part (frontmatter?, body, end?, note*)>
<!ELEMENT chapter (frontmatter?, body, end?, note*)>
<!ELEMENT subchapter (paragraph | note)*>

<!ELEMENT paragraph (#PCDATA  | poem | reference | emp | ital | quote | html:span)*>
<!ATTLIST paragraph class CDATA #IMPLIED>

<!ELEMENT html:span (#PCDATA)>
<!ATTLIST html:span style CDATA #IMPLIED>

<!ELEMENT poem (line)*>
<!ELEMENT line (#PCDATA)>
<!ELEMENT emp (#PCDATA)>
<!ELEMENT ital (#PCDATA)>
<!ELEMENT quote (#PCDATA)>
<!ELEMENT reference (#PCDATA)>
<!ATTLIST reference type (footnote-num | footnote-ref)  #REQUIRED
                        ref ID                              #IMPLIED>

<!ELEMENT note (paragraph*)>
<!ATTLIST note      class   CDATA   #REQUIRED
                    id      IDREF   #IMPLIED>

<!ELEMENT end (appendix | bibliography | endnotes | glossary | index | note )*>

<!ENTITY mdash   "&#8212;" >    <!-- em dash -->
<!ENTITY lsquo   "&#8216;" >    <!-- left single quotation mark -->
<!ENTITY rsquo   "&#8217;" >    <!-- right single quotation mark -->
<!ENTITY ldquo   "&#8220;" >    <!-- left double quotation mark -->
<!ENTITY rdquo   "&#8221;" >    <!-- right double quotation mark -->
<!ENTITY nbsp    "&#160;"  >    <!-- nonbreaking space -->

很明显,我期望不会有任何错误,但是当我进入验证器时,我会得到 上面的两个错误。

0 个答案:

没有答案