My address.dtd file is as follows. When I tried to parse my address.xml file using SAXParserFactory, the exception come as,
"org.xml.sax.SAXParseException; systemId: file:/home/samitha/svnrepo/XML/XMLParserTest/src/address.dtd; lineNumber: 9; columnNumber: 22; Open quote is expected for attribute "{1}" associated with an element type "province"."
<!-- address.dtd -->
<!ELEMENT address (name,house-id?,village,city,postal-code,country) >
<!ELEMENT name (personal:title*,(first-name|first-init),last-name+)>
<!ELEMENT house-id (houses:title,NAME)>
<!ELEMENT personal:name (#PCDATA) >
<!ELEMENT village (#PCDATA) >
<!ELEMENT city (#PCDATA) >
<!ATTLIST city district CDATA #REQUIRED
province CDATA (Southern|Western|Nothern|Eastern) "One Sri
Lanka">
<!ELEMENT postal-code (#PCDATA) >
<!ELEMENT country (#PCDATA) >
<!ELEMENT personal:title (#PCDATA) >
<!ELEMENT first-name (#PCDATA) >
<!ELEMENT first-init (#PCDATA) >
<!ELEMENT last-name (#PCDATA) >
<!ELEMENT houses:title (#PCDATA) >
<!ELEMENT NAME (#PCDATA) >
address.xml file looks as follows.
<?xml version ="1.0" encoding="UTF-8"?>
<!DOCTYPE address SYSTEM "address.dtd">
<!-- Some namespaces are declared in this-->
<address
xmlns:personal="Personal things"
xmlns:houses="Regarding to houses"
>
<name xml:space='preserve'>
<personal:title>Mr. </personal:title>
<first-name>Samitha </first-name>
<last-name>Chathuranga</last-name>
</name>
<house-id>
<houses:title>107 B</houses:title>
<NAME>Sam's Home</NAME>
<!-- An intnal entity is used for the single quote in House Name here-->
</house-id>
<village>Poramba</village>
<city district="Galle" province="Southern">AG</city>
<postal-code>80300</postal-code>
<country>Sri Lanka</country>
</address>
An attribute's datatype can be an enumeration or CDATA, but it can't be both. You should remove the CDATA
:
<!ATTLIST city
district CDATA #REQUIRED
province (Southern|Western|Nothern|Eastern) "One Sri Lanka">
Source: http://www.xmlfiles.com/dtd/dtd_attributes.asp
However there's still a problem here. The value "One Sri Lanka" does not match any of the four values you have listed there. What is your thinking behind that?