address.xml如下
<!--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'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>
使用java SAX解析器验证时的错误是
“Attribute”xmlns“必须为元素类型”address“声明。 必须为元素类型“address”声明属性“xmlns:xsd”。 必须为元素类型“address”声明属性“xsd:schemaLocation”。“
但如果我删除引用3行的xsd,则不会出现错误。这些行是,
xmlns="http://www.w3schools.com"
xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance"
xsd:schemaLocation="address.xsd"
答案 0 :(得分:1)
有许多问题需要解决:
DOCTYPE
)和XML架构(通过
xsd:schemaLocation
)。<?xml version ="1.0"
encoding="UTF-8"?>
),但它不在文件的第一行。schemaLocation
值不是
名称空间 - 模式对。