此DTD声明是否正确措词?

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

XML和DTD的新手,试图做一个家庭作业,因此得到了DTD,但我需要写出XML内容并进行解析。

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

<!ELEMENT ConutryList (CountryReccord) +>
<!ATTLIST CountryList
  xmlns CDATA #FIXED ' '>

<!ELEMENT CountryRecord (name,alpha-2,alpha-3,country-code,iso_3166-2,region,sub-region,intermediate-region,region-code,sub-region-code,
intermediate-region-code,capital-city,currency,currency-code, population)>

<!ATTLIST CountryRecord
  xmlns CDATA #FIXED ' '>

<CountryList>
  <CountryRecord>
  <name> Afganistan </name>
  <alpha-2> AF </alpha-2>
  <country-code> AFG </country-code>
  <iso_3166-2>
  <region>
  <sub-region>
  <intermediate-region>
  <region-code>
  <sub-region-code>
  <intermediate-region-code>
  <capital-city>
  <currency>
  <currency-code>
  <population>
  </CountryRecord>
</CountryList>

这是我的编码格式正确吗?我对此不太确定,害怕不得不重新启动所有操作。我正在处理大量清单。任何帮助,将不胜感激!

xml dtd
1个回答
0
投票

这里有很多错误,很难知道从哪里开始。我很快注意到的前四个是(a)DTD必须在DOCTYPE声明中,(b)实例中需要一个alpha-3元素,(c)CountryRecord需要具有xmlns属性(DTD是无法识别名称空间,并将名称空间声明视为普通属性)(d)大多数子元素没有结束符。

但是退后一步,更深层次的事情是错误的,这就是您获取信息和解决问题的方法。您不应该在StackOverflow上问这个问题。您应该阅读教科书,使教程中的示例生效,并在编写任何代码之前学习概念和原则。当出现问题时,您应该查看错误消息,并以它们为指导来找出问题所在。

© www.soinside.com 2019 - 2024. All rights reserved.