XML entity include not displaying

让人想犯罪 __ 提交于 2019-12-13 04:21:21

问题


I am attempting to include an entity within my xml, however, it doesn't seem to be displaying. I'm very new to XML, so if what I've found in my research isn't best practice, I'm more than open to changing.

XML to Include

<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 for inclusion

<?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)>

回答1:


The word that comes after DOCTYPE must be the document root element (replace downloadWord with thing):

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE thing SYSTEM "resume.dtd"[
    <!ENTITY resume SYSTEM "resume.xml">
]>
<thing>
    &resume;
</thing>

That should include the file (which will cause validation errors, since the document doesn't match the DTD. To fix the DTD so it matches the instance (you might want to do the opposite):

Line 2: Change personalinfo in to personal_info:

<!ELEMENT resume (personal_info, jobs)>

Line 5: Replace jobs with job:

<!ELEMENT job (company,title,startdate,enddate,duration,sortdate)>

Add this new line:

<!ELEMENT jobs (job+)>

This is the final resume.dtd DTD which validates the file above:

<!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)>


来源:https://stackoverflow.com/questions/24196139/xml-entity-include-not-displaying

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!