【问题标题】:XML - DTD IssueXML - DTD 问题
【发布时间】:2018-05-10 05:06:51
【问题描述】:

我正在尝试将 DTD 应用于 XML 文档(我是 XML 新手)。我在代码中收到以下错误。除此之外还有更好的方法来应用DTD吗?

<!DOCTYPE chat [
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>

<chat>
<note>
  <to>Tove</to>
  <from>Jani</from>
  <heading>Reminder</heading>
  <body>Don't forget me this weekend!</body>
</note>
<note>
  <to>Tove</to>
  <from>Jani</from>
  <heading>Reminder</heading>
  <body>Don't forget me this weekend!</body>
</note>
</chat>

错误

必须声明元素类型“聊天”。

【问题讨论】:

    标签: xml dtd


    【解决方案1】:

    Part - 试试这个

    <!DOCTYPE chat [
    <!ELEMENT chat (note*)>
    <!ELEMENT note (to,from,heading,body)>
    <!ELEMENT to (#PCDATA)>
    <!ELEMENT from (#PCDATA)>
    <!ELEMENT heading (#PCDATA)>
    <!ELEMENT body (#PCDATA)>
    ]>
    

    【讨论】:

    • 谢谢!现在可以了。你能解释一下为什么需要你添加的那行吗?
    • 对于每个元素,您需要定义其子元素和出现次数。
    • 好的。这有帮助。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-28
    • 1970-01-01
    • 1970-01-01
    • 2012-09-22
    • 2016-04-23
    • 1970-01-01
    相关资源
    最近更新 更多