Is this DTD declaration correctly phrased?

廉价感情. 提交于 2020-01-06 05:57:11

问题


New to XML and DTD, trying to do a homework whereby I was given the DTD but I need to write out the XML content and parse it.

<?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>

Is this my format of coding correct? I am very unsure of it, scared to have to restart everything. There is a huge list im working on it. Any help would be appreciated!


回答1:


There are so many things wrong here it's hard to know where to start. The first four I noticed very quickly are (a) the DTD needs to be in a DOCTYPE declaration, (b) there needs to be an alpha-3 element in the instance, (c) CountryRecord needs to have an xmlns attribute (DTDs are not namespace aware, and treat namespace declarations as ordinary attributes) (d) most of the child elements have no closing end tag.

But step back, and something deeper is wrong, and that's your approach to getting information and solving problems. You shouldn't be asking this on StackOverflow. You should be reading textbooks, getting examples in tutorials to work, learning the concepts and principles before you write any code; and when things don't work, you should be looking at the error messages and using them as guidance to find out what's wrong.



来源:https://stackoverflow.com/questions/58778151/is-this-dtd-declaration-correctly-phrased

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!