Question

address.xml is as follows

<!--address.xml-->
<?xml version ="1.0" encoding="UTF-8"?>
<!DOCTYPE address SYSTEM "address.dtd">
<address 

    xmlns:personal="Personal things"
    xmlns:houses="Regarding to houses"  

    xmlns="http://www.w3schools.com" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance"
    xsd:schemaLocation="address.xsd"

>
    <name>  
        <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&apos;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>

The errors when validated using java SAX parser are,

"Attribute "xmlns" must be declared for element type "address". Attribute "xmlns:xsd" must be declared for element type "address". Attribute "xsd:schemaLocation" must be declared for element type "address"."

But if I removed the xsd referencing 3 lines, no errors come. Those lines are,

xmlns="http://www.w3schools.com" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance"
xsd:schemaLocation="address.xsd"
Was it helpful?

Solution

There are a number of problems to address:

  1. You are specifying both a DTD (via DOCTYPE) and an XML Schema (via xsd:schemaLocation).
  2. You are specifying an XML declaration (<?xml version ="1.0" encoding="UTF-8"?>), but it is not on the first line of the file.
  3. You are specifying a schemaLocation value that is not in terms of namespace-schema pairs.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top