问题
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