我试图在我的xml中包含一个实体,但是,它似乎没有显示。我对XML非常陌生,所以如果我在研究中发现的不是最佳实践,那么我对改变是开放的。
要包含的XML
<resume>
<personal_info>
<birthdate>07/08/1988</birthdate>
</personal_info>
<jobs>
<job>
<company>Radio Shack</company>
<title>Sales Representative</title>
<startdate>01/01/2011</startdate>
<enddate>02/02/2011</enddate>
<duration>1.5yrs</duration>
<sortdate>20110101</sortdate>
</job>
<job>
<company>Radio Shack2</company>
<title>Sales Representative</title>
<startdate>01/01/2013</startdate>
<enddate>02/02/2013</enddate>
<duration>1.5yrs</duration>
<sortdate>20130202</sortdate>
</job>
</jobs>
</resume>
包含XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE downloadWord SYSTEM "resume.dtd"[
<!ENTITY resume SYSTEM "resume.xml">
]>
<thing>
&resume;
</thing>
DTD
<!ELEMENT thing (resume)>
<!ELEMENT resume (personalinfo, jobs)>
<!ELEMENT personalinfo (birthdate)>
<!ELEMENT birthdate (#PCDATA)>
<!ELEMENT jobs (company,title,startdate,enddate,duration,sortdate)>
<!ELEMENT company (#PCDATA)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT startdate (#PCDATA)>
<!ELEMENT enddate (#PCDATA)>
<!ELEMENT duration (#PCDATA)>
<!ELEMENT sortdate (#PCDATA)>
答案 0 :(得分:2)
DOCTYPE
之后的字必须是文档根元素(将downloadWord
替换为thing
):
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE thing SYSTEM "resume.dtd"[
<!ENTITY resume SYSTEM "resume.xml">
]>
<thing>
&resume;
</thing>
那应该包含文件(这将导致验证错误,因为文档与DTD不匹配。要修复DTD以使其与实例匹配(您可能希望执行相反的操作):
第2行:将personalinfo
更改为personal_info
:
<!ELEMENT resume (personal_info, jobs)>
第5行:将jobs
替换为job
:
<!ELEMENT job (company,title,startdate,enddate,duration,sortdate)>
添加新行:
<!ELEMENT jobs (job+)>
这是验证上述文件的最终resume.dtd
DTD:
<!ELEMENT thing (resume)>
<!ELEMENT resume (personal_info, jobs)>
<!ELEMENT personal_info (birthdate)>
<!ELEMENT birthdate (#PCDATA)>
<!ELEMENT jobs (job+)>
<!ELEMENT job (company,title,startdate,enddate,duration,sortdate)>
<!ELEMENT company (#PCDATA)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT startdate (#PCDATA)>
<!ELEMENT enddate (#PCDATA)>
<!ELEMENT duration (#PCDATA)>
<!ELEMENT sortdate (#PCDATA)>