外部DTDマークアップ宣言が必要です[重複]

Nov 30 2020

外部DTD検証を追加すると、XML検証に問題があります。これは正常に機能します。

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE booklist [
<!ELEMENT booklist (book)*>
<!ELEMENT book (author,title,published?)>
<!ELEMENT author (firstname,lastname)>
<!ELEMENT firstname (#PCDATA)>
<!ELEMENT lastname (#PCDATA)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT published (#PCDATA)>
<!ATTLIST book genre (Science|Fiction) #REQUIRED>
<!ATTLIST book format (Paperback|Hardcover) "Paperback">
]>
<booklist>
  <book genre="Fiction" format="Paperback">
    <author>
      <firstname>Name</firstname>
      <lastname>Surname</lastname>
    </author>
    <title>Sample</title>
    <published>2020</published>
  </book>
</booklist>

外部のdtd宣言を追加しようとすると、XMLコピーエディターがエラーを出力します

1行3列目の致命的なエラー:マークアップ宣言が必要です

XML

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE booklist SYSTEM "booklist.dtd">
<booklist>
  <book genre="Fiction" format="Paperback">
    <author>
      <firstname>Name</firstname>
      <lastname>Surname</lastname>
    </author>
    <title>Sample</title>
    <published>2020</published>
  </book>
</booklist>

DTD

<!DOCTYPE booklist [
<!ELEMENT booklist (book)*>
<!ELEMENT book (author,title,published?)>
<!ELEMENT author (firstname,lastname)>
<!ELEMENT firstname (#PCDATA)>
<!ELEMENT lastname (#PCDATA)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT published (#PCDATA)>
<!ATTLIST book genre (Science|Fiction) #REQUIRED>
<!ATTLIST book format (Paperback|Hardcover) "Paperback">
]>

私は何が間違っているのですか?

回答

1 kjhughes Dec 01 2020 at 00:17

DOCTYPE外部サブセットのラッパーを削除します。

外部DTD

<!ELEMENT booklist (book)*>
<!ELEMENT book (author,title,published?)>
<!ELEMENT author (firstname,lastname)>
<!ELEMENT firstname (#PCDATA)>
<!ELEMENT lastname (#PCDATA)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT published (#PCDATA)>
<!ATTLIST book genre (Science|Fiction) #REQUIRED>
<!ATTLIST book format (Paperback|Hardcover) "Paperback">