英文:
XML Unexpected element, content of the parent element must match type
问题
I'm new to XML (and new to stackoverflow) and I'm trying to write an XML file & an accompanying DTD file containing some basic information about geographic subdivisions (states and provinces). The first of my
Unexpected element "Subdivision". The content of the parent element type must match "(Subdivision)".
I'm not sure what's causing the first one to work and the second one to error, I'm probably missing something but I can't figure out what it is.
Here's the XML code in question, somewhat trimmed:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Subdivisions SYSTEM "Subdivision.dtd">
<Subdivisions>
<Subdivision subdivisionName = "Nebraska">
<official_name>State of Nebraska</official_name>
<country>United States</country>
<iso_3166_code>US-NE</iso_3166_code>
<regional_capital>Lincoln</regional_capital>
<population>1961504</population>
<land_area_miles>77358</land_area_miles>
</Subdivision>
<Subdivision subdivisionName = "Southwest Finland"> <!-- the error is on this line-->
<official_name>Southwest Finland</official_name>
<country>Finland</country>
<iso_3166_code>FI-19</iso_3166_code>
<regional_capital>Turku</regional_capital>
<population>481403</population>
<land_area_miles>4212</land_area_miles>
</Subdivision>
<!-- trimmed the rest -->
</Subdivisions>
And the DTD that goes with it:
<?xml encoding="UTF-8">
<!ELEMENT Subdivisions (Subdivision)>
<!ELEMENT Subdivision (official_name, country, iso_3166_code, regional_capital, population, land_area_miles)>
<!ELEMENT official_name (#PCDATA)>
<!ELEMENT country (#PCDATA)>
<!ELEMENT iso_3166_code (#PCDATA)>
<!ELEMENT regional_capital (#PCDATA)>
<!ELEMENT population (#PCDATA)>
<!ELEMENT land_area_miles (#PCDATA)>
<!ATTLIST Subdivision subdivisionName CDATA #REQUIRED>
This is my first time doing XML and my first time asking a StackOverflow question so I apologize if I did it wrong or provided too little (or too much?) context/code.
Any help is greatly appreciated!
英文:
I'm new to XML (and new to stackoverflow) and I'm trying to write an XML file & an accompanying DTD file containing some basic information about geographic subdivisions (states and provinces). The first of my <Subdivision> elements is working fine, but oXygen is giving me the following error at the start of the second <Subdivision> element:
> Unexpected element "Subdivision". The content of the parent element type must match "(Subdivision)".
I'm not sure what's causing the first one to work and the second one to error, I'm probably missing something but I can't figure out what it is.
Here's the XML code in question, somewhat trimmed:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Subdivisions SYSTEM "Subdivision.dtd">
<Subdivisions>
<Subdivision subdivisionName = "Nebraska">
<official_name>State of Nebraska</official_name>
<country>United States</country>
<iso_3166_code>US-NE</iso_3166_code>
<regional_capital>Lincoln</regional_capital>
<population>1961504</population>
<land_area_miles>77358</land_area_miles>
</Subdivision>
<Subdivision subdivisionName = "Southwest Finland"> <!-- the error is on this line-->
<official_name>Southwest Finland</official_name>
<country>Finland</country>
<iso_3166_code>FI-19</iso_3166_code>
<regional_capital>Turku</regional_capital>
<population>481403</population>
<land_area_miles>4212</land_area_miles>
</Subdivision>
<!-- trimmed the rest -->
</Subdivisions>
And the DTD that goes with it:
<?xml encoding="UTF-8"?>
<!ELEMENT Subdivisions (Subdivision)>
<!ELEMENT Subdivision (official_name, country, iso_3166_code, regional_capital, population, land_area_miles)>
<!ELEMENT official_name (#PCDATA)>
<!ELEMENT country (#PCDATA)>
<!ELEMENT iso_3166_code (#PCDATA)>
<!ELEMENT regional_capital (#PCDATA)>
<!ELEMENT population (#PCDATA)>
<!ELEMENT land_area_miles (#PCDATA)>
<!ATTLIST Subdivision subdivisionName CDATA #REQUIRED>
This is my first time doing XML and my first time asking a StackOverflow question so I apologize if I did it wrong or provided too little (or too much?) context/code.
Any help is greatly appreciated!
答案1
得分: 2
朋友告诉我一个解决方案,解决了我的问题,我不知道在 DTD 文件中可以使用 + 符号表示一个元素存在一个或多个。
将这行代码更改为:
<!ELEMENT Subdivisions (Subdivision+)>
英文:
My friend told me a solution that solved my problem, I didn't know that you can use the + symbol in the DTD file to indicate that there are one or more of an element.
Changed the line
<!ELEMENT Subdivisions (Subdivision)>
to this:
<!ELEMENT Subdivisions (Subdivision+)>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论