下午好,我还是XMl和DTD的新手,但我同时也很开心。我有一个简单的任务,我已经命名为“联系人”,但我很难获得DTD验证。我当然缺少一些东西,希望得到一些提示或一些帮助。代码如下,错误低于代码。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Contacts [
<!ELEMENT Contacts (XYZ, ABC, WIZ)>
<!ELEMENT XYZ (#PCDATA)>
<!ELEMENT ABC (#PCDATA)>
<!ELEMENT WIZ (#PCDATA)>
]>
<Contacts>
<XYZ>
"XYZ Inc.",
"Jones","Barnaby"
"bjones@xyz.com"
"Owner-Operator"
"402-410-2314"
"8923 Holmes St"
"Omaha","NE","68222","USA"
"<div>Prospect</div>"
"Business"
</XYZ>
<ABC>
"ABC International"
"Magnum","Thomas"
"tmagnum@abcint.biz"
"Owner-Operator"
"402-310-2222"
"402-571-2893"
"3204 Plains Ave"
"Papillion","NE","68103","USA"
"<div>Vendor</div>"
"Business"
</ABC>
<Wiz>"Wiz Kids"
"Plum","Steve"
"steve@wizkids.com"
"Sales Rep"
"402-555-2325"
"402-516-2038"
"402-333-2428"
"1234 Main St"
"Belluvue","NE","68201","USA
#http://wizkids.com#
<div>Vendor</div>"
</Wiz>
</Contacts>
错误:
答案 0 :(得分:0)
使用CDATA将内容包装在xml中,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Contacts [
<!ELEMENT Contacts (XYZ)>
<!ELEMENT XYZ (#PCDATA)>
]>
<Contacts>
<XYZ>
<![CDATA["XYZ Inc.",
"Jones","Barnaby"
"bjones@xyz.com"
"Owner-Operator"
"402-410-2314"
"8923 Holmes St"
"Omaha","NE","68222","USA"
"<div>Prospect</div>"
"Business"]]>
</XYZ>
</Contacts>
或者将div添加到元素定义中:
<!ELEMENT XYZ (#PCDATA|div)>
或定义“&lt;”和“&gt;” DTD中的实体并使用它们而不是实际的“&lt;”和“&gt;”在内容中:
<!ENTITY lt "<">
<!ENTITY gt ">">
<XYZ>
<Prospect>
</XYZ>
请记住,XML标记区分大小写,因此要么定义元素Wiz,要么在内容中将其称为WIZ。
另外,请查看本教程:http://www.w3schools.com/dtd/default.asp