XML错误:对于与元素类型关联的属性id,需要打开引号

时间:2016-06-26 14:49:45

标签: java xml sax parseexception

我正在尝试解析下面显示的XML文件:

<?xml version="1.0"?>
<!DOCTYPE COUNTRIES_CONTINENT PUBLIC 
           "-//XYZ//DTD Declarations(CountriesContinent)//EN" "dtds/countries_continent.dtd">
<COUNTRIES_CONTINENT>
   <CONTINENT id="6" name="Oceania" value="12">
       <COUNTRY name="Argentina"/>
       <COUNTRY name="Bolivia"/>
       <COUNTRY name="Brazil"/>
       <COUNTRY name="Chile"/>
        <COUNTRY name="Colombia"/>
        <COUNTRY name="Ecuador"/>
        <COUNTRY name="Guyana"/>
        <COUNTRY name="Paraguay"/>
        <COUNTRY name="Peru"/>
        <COUNTRY name="Suriname"/>
        <COUNTRY name="Uruguay"/>
        <COUNTRY name="Venezuela"/>
    </CONTINENT>
</COUNTRIES_CONTINENT>

拥有以下DTD文件:

<!ELEMENT COUNTRIES_CONTINENT (CONTINENT+)>
<!ELEMENT CONTINENT (COUNTRY+)>
<!ELEMENT COUNTRY EMPTY>
<!ATTLIST CONTINENT id  CDATA  ID #REQUIRED>
<!ATTLIST CONTINENT name  CDATA #REQUIRED>
<!ATTLIST CONTINENT value CDATA #REQUIRED>
<!ATTLIST COUNTRY   name CDATA #REQUIRED>

我收到以下异常:

Open quote is expected for the attribute "id" associated with an element type "CONTINENT".

有谁可以指出出了什么问题?

1 个答案:

答案 0 :(得分:2)

<!ATTLIST CONTINENT id  CDATA  ID #REQUIRED>

属性类型可以是CDATAID,但不能同时属于两者。这些类型中的每一种都有自己的规则,描述了允许它们包含的值的范围。请检查id的预期类型。

请参阅http://www.w3schools.com/xml/xml_dtd_attributes.asp