.
在线验证:http: //xmlvalidator.new-studio.org
XML 文档 (也显示在下方)
问题 1
当我取消注释以下行号时。4
<!ELEMENT persona (#PCDATA|(name,dob?,address*)) >
并评论以下行号。5
<!ELEMENT persona (name,dob?,address*) >
为什么会显示以下错误?
- 第 4 行第 28 列:元素类型“persona”的声明中需要元素类型。
在这里,我希望用户可以使用可解析的字符串,也可以编写姓名、dob 和地址标签并在其中写入信息。
问题2
当我将编码从“ISO-8859-1”替换为“utf-8”,并在浏览器(谷歌浏览器)中加载页面时;它显示以下错误。
error on line 2 at column 21: Encoding error
但验证成功& OK。
为什么会显示该错误? 哪种编码好?
带有嵌入式 DTD 的 XML 文档
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE personality [
<!ELEMENT personality (persona*) >
<!-- <!ELEMENT persona (#PCDATA|(name,dob?,address*)) > -->
<!ELEMENT persona (name,dob?,address*) >
<!-- <!ELEMENT name (#PCDATA|(first_name,last_name)) > -->
<!ELEMENT name (first_name,last_name) >
<!ELEMENT first_name (#PCDATA) >
<!ELEMENT last_name (#PCDATA) >
<!ELEMENT dob (date+,month+,year+) >
<!ELEMENT date (#PCDATA) >
<!ELEMENT month (#PCDATA) >
<!ELEMENT year (#PCDATA) >
<!ELEMENT address (building,street,city,state,country,country_code) >
<!ELEMENT building (#PCDATA) >
<!ELEMENT street (#PCDATA) >
<!ELEMENT city (#PCDATA) >
<!ELEMENT state (#PCDATA) >
<!ELEMENT country (#PCDATA) >
<!ELEMENT country_code (#PCDATA) >
<!ATTLIST persona id ID #REQUIRED >
<!ATTLIST name type (string|number) "string" >
<!ATTLIST dob type (string|number) "number" >
<!ATTLIST address type (string|number) "string" >
<!ENTITY author "Miguel Pitts" >
<!ENTITY website "example.com" >
<!ENTITY email "miguelpitts4MN@teleosaurs.xyz" >
<!ENTITY copyright "Copyright © Miguel Pitts" >
]>
<?xml-stylesheet type="text/css" href="xmlstyle.css" ?>
<personality>
<persona id="p1">
<name type="string">
<first_name>Miguel</first_name>
<last_name>Pitts</last_name>
</name>
<dob type="number">
<date>12</date>
<month>02</month>
<year>1989</year>
</dob>
<address type="string">
<building>1233</building>
<street>15</street>
<city>NY</city>
<state>Bangkok</state>
<country>China</country>
<country_code>82</country_code>
</address>
</persona>
</personality>