为什么外部DTD没有验证XML文件?

问题描述 投票:0回答:1

我需要外部DTD来验证XML文件和'选择''手机'和'手机'不断出现错误。我知道它与我的元素顺序有关,但我无法弄明白。

我编辑了。元素手机和手机,我相信它现在正在验证

DTD

     [
        <!ELEMENT smartphones (choices+)>

        <!ELEMENT choices (phones,phone,name,company,price,storage,description)>
        <!ATTLIST choices phones NMTOKENS #REQUIRED>

    <!ELEMENT phones (phone)>
    <!ATTLIST phones CDATA #REQUIRED>

    <!ELEMENT phone (name,company,price,storage,description)>
    <!ATTLIST phone NMTOKENS #REQUIRED>

        <!ELEMENT name (#PCDATA)>

        <!ELEMENT company (#PCDATA)>

        <!ELEMENT price (#PCDATA)>

        <!ELEMENT storage (#PCDATA)>

        <!ELEMENT description (#PCDATA)>

        ]>

<!-- XML -->
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>

<!DOCTYPE smartphones SYSTEM "Vocab1DTD.dtd">

<smartphones>

<choices>Smart Phones

   <phones>
      <phone>
         <name> </name>
         <company> </company>
         <price> </price>
         <storage> </storage>
         <description> </description>
      </phone>

  </phones>
</choices>
</smartphones>
xml validation dtd
1个回答
0
投票

这是一个更新的DTD,可以按原样使用XML。

关于XML的小评论:在choices中将“智能手机”作为文本并没有多大意义;可以推断,choicessmartphones的孩子。此外,choicesphones似乎多余;两者的目的是什么?

如果您对我所做的更改有疑问,请与我们联系。

Vocab1DTD.dtd

<!ELEMENT smartphones (choices+)>
<!ELEMENT choices (#PCDATA|phones)*>
<!ELEMENT phones (phone+)>
<!ELEMENT phone (name,company,price,storage,description)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT company (#PCDATA)>
<!ELEMENT price (#PCDATA)>
<!ELEMENT storage (#PCDATA)>
<!ELEMENT description (#PCDATA)>
© www.soinside.com 2019 - 2024. All rights reserved.