2015-09-27 70 views
2

我有一個XML文件,我試圖根據DTD進行驗證(在與XML相同的本地文件夾中)。 XML檢出格式良好,但每次嘗試在記事本++中對DTD進行驗證都會導致「無法加載DTD PresidentsDTD.dtd」錯誤。任何想法我需要做些什麼來得到這個工作?記事本++根據本地DTD驗證XML

XML文件:

<?xml version="1.0" standalone="no"?> 
<!DOCTYPE LIST SYSTEM "PresidentsDTD.dtd"> 

<LIST> 
<PRESIDENT id="01" gender="male" name="GeorgeWashington"> 
    <NAME> 
     <FIRST>George</FIRST> 
     <MIDDLE /> 
     <LAST>Washington</LAST> 
    </NAME> 
    <TERM count="2"> 
     <TERMSTART>1789</TERMSTART> 
     <TERMEND>1797</TERMEND> 
     <TERML unit="years"> 8 </TERML> 
    </TERM> 
    <PARTY>N/A</PARTY> 
    <HOMESTATE>Virginia</HOMESTATE> 
</PRESIDENT> 

<PRESIDENT id="02" gender="male" name="JohnAdams"> 
    <NAME> 
     <FIRST>John</FIRST> 
     <MIDDLE /> 
     <LAST>Adams</LAST> 
    </NAME> 
    <TERM count="2">  
     <TERMSTART>1797</TERMSTART> 
     <TERMEND>1801</TERMEND> 
     <TERML unit="years"> 8 </TERML> 
    </TERM> 
    <PARTY>Federalist</PARTY> 
    <HOMESTATE>Massachusetts</HOMESTATE> 
</PRESIDENT> 

<PRESIDENT id="03" gender="male" name="ThomasJefferson"> 
    <NAME> 
     <FIRST>Thomas</FIRST> 
     <MIDDLE /> 
     <LAST>Jefferson</LAST> 
    </NAME> 
    <TERM count="2"> 
     <TERMSTART>1801</TERMSTART> 
     <TERMEND>1809</TERMEND> 
     <TERML unit="years"> 8 </TERML> 
    </TERM> 
    <PARTY>Republican-Democrat</PARTY> 
    <HOMESTATE>Virginia</HOMESTATE> 
</PRESIDENT> 

<PRESIDENT id="07" gender="male" name="AndrewJackson"> 
    <NAME> 
     <FIRST>Andrew</FIRST> 
     <MIDDLE /> 
     <LAST>Jackson</LAST> 
    </NAME> 
    <TERM count="2"> 
     <TERMSTART>1829</TERMSTART> 
     <TERMEND>1837</TERMEND> 
     <TERML unit="years"> 8 </TERML> 
    </TERM> 
    <PARTY>Democrat</PARTY> 
    <HOMESTATE>Tennesee</HOMESTATE> 
</PRESIDENT> 

<PRESIDENT id="09" gender="male" name="WilliamHenryHarrison"> 
    <NAME> 
     <FIRST>William</FIRST> 
     <MIDDLE>Henry</MIDDLE> 
     <LAST>Harrison</LAST> 
    </NAME> 
    <TERM count="1"> 
     <TERMSTART>1841</TERMSTART> 
     <TERMEND>1841</TERMEND> 
     <TERML unit="months"> 1 </TERML> 
    </TERM> 
    <PARTY>Whig</PARTY> 
    <HOMESTATE>Ohio</HOMESTATE> 
</PRESIDENT> 

<PRESIDENT id="15" gender="male" name="AbrahamLincoln"> 
    <NAME> 
     <FIRST>Abraham</FIRST> 
     <MIDDLE /> 
     <LAST>Lincoln</LAST> 
    </NAME> 
    <TERM count="2"> 
     <TERMSTART>1861</TERMSTART> 
     <TERMEND>1865</TERMEND> 
     <TERML unit="years"> 4 </TERML> 
    </TERM> 
    <PARTY>Republican</PARTY> 
    <HOMESTATE>Illinois</HOMESTATE> 
</PRESIDENT> 
</LIST> 

我PresidentsDTD.dtd文件(在第2行還是返回一個錯誤出於某種原因):

<!DOCTYPE LIST[ 
<!ELEMENT LIST PRESIDENT+> 
<!ELEMENT PRESIDENT (NAME, TERM, PARTY, HOMESTATE)> 
<!ATTLIST PRESIDENT id ID #REQUIRED> 
<!ATTLIST PRESIDENT gender (male | female) #IMPLIED> 
<!ATTLIST PRESIDENT name CDATA #IMPLIED> 
<!ELEMENT NAME (FIRST, MIDDLE?, LAST)> 
<!ELEMENT TERM (TERMSTART, TERMEND, TERMLENGTH)> 
<!ATTLIST TERM count CDATA #IMPLIED> 
<!ELEMENT FIRST (#PCDATA)> 
<!ELEMENT MIDDLE (#PCDATA)> 
<!ELEMENT LAST (#PCDATA)> 
<!ELEMENT TERMSTART (#PCDATA)> 
<!ELEMENT TERMEND (#PCDATA)> 
<!ELEMENT TERMLENGTH (#PCDATA)> 
<!ATTLIST TERMLENGTH unit (months | years) #IMPLIED> 
]> 

沒有人有驗證針對DTD本地的解決方案?

回答

1

我編輯了你的XML和.dtd文件。現在XML是有效的。注意,在文件中,我添加了關於你的錯誤的評論。 XML文件:

<?xml version="1.0" standalone="no"?> 
    <!DOCTYPE LIST SYSTEM "PresidentsDTD.dtd"> 
    <LIST> 
    <PRESIDENT id="ID01" gender="male" name="GeorgeWashington"> <!--id must be unique--> 
     <NAME> 
      <FIRST>George</FIRST> 
      <MIDDLE /> 
      <LAST>Washington</LAST> 
     </NAME> 
     <TERM count="2"> 
      <TERMSTART>1789</TERMSTART> 
      <TERMEND>1797</TERMEND> 
      <TERMLENGTH unit="years"> 8 </TERMLENGTH> <!--You have <TERML> in XML and <TERMLENGTH> in .dtd--> 
     </TERM> 
     <PARTY>N/A</PARTY> 
     <HOMESTATE>Virginia</HOMESTATE> 
    </PRESIDENT> 

    <PRESIDENT id="ID02" gender="male" name="JohnAdams"> 
     <NAME> 
      <FIRST>John</FIRST> 
      <MIDDLE /> 
      <LAST>Adams</LAST> 
     </NAME> 
     <TERM count="2">  
      <TERMSTART>1797</TERMSTART> 
      <TERMEND>1801</TERMEND> 
      <TERMLENGTH unit="years"> 8 </TERMLENGTH> 
     </TERM> 
     <PARTY>Federalist</PARTY> 
     <HOMESTATE>Massachusetts</HOMESTATE> 
    </PRESIDENT> 

    <PRESIDENT id="ID03" gender="male" name="ThomasJefferson"> 
     <NAME> 
      <FIRST>Thomas</FIRST> 
      <MIDDLE /> 
      <LAST>Jefferson</LAST> 
     </NAME> 
     <TERM count="2"> 
      <TERMSTART>1801</TERMSTART> 
      <TERMEND>1809</TERMEND> 
      <TERMLENGTH unit="years"> 8 </TERMLENGTH> 
     </TERM> 
     <PARTY>Republican-Democrat</PARTY> 
     <HOMESTATE>Virginia</HOMESTATE> 
    </PRESIDENT> 

    <PRESIDENT id="ID07" gender="male" name="AndrewJackson"> 
     <NAME> 
      <FIRST>Andrew</FIRST> 
      <MIDDLE /> 
      <LAST>Jackson</LAST> 
     </NAME> 
     <TERM count="2"> 
      <TERMSTART>1829</TERMSTART> 
      <TERMEND>1837</TERMEND> 
      <TERMLENGTH unit="years"> 8 </TERMLENGTH> 
     </TERM> 
     <PARTY>Democrat</PARTY> 
     <HOMESTATE>Tennesee</HOMESTATE> 
    </PRESIDENT> 

    <PRESIDENT id="ID09" gender="male" name="WilliamHenryHarrison"> 
     <NAME> 
      <FIRST>William</FIRST> 
      <MIDDLE>Henry</MIDDLE> 
      <LAST>Harrison</LAST> 
     </NAME> 
     <TERM count="1"> 
      <TERMSTART>1841</TERMSTART> 
      <TERMEND>1841</TERMEND> 
      <TERMLENGTH unit="months"> 1 </TERMLENGTH> 
     </TERM> 
     <PARTY>Whig</PARTY> 
     <HOMESTATE>Ohio</HOMESTATE> 
    </PRESIDENT> 

    <PRESIDENT id="ID15" gender="male" name="AbrahamLincoln"> 
     <NAME> 
      <FIRST>Abraham</FIRST> 
      <MIDDLE /> 
      <LAST>Lincoln</LAST> 
     </NAME> 
     <TERM count="2"> 
      <TERMSTART>1861</TERMSTART> 
      <TERMEND>1865</TERMEND> 
      <TERMLENGTH unit="years"> 4 </TERMLENGTH> 
     </TERM> 
     <PARTY>Republican</PARTY> 
     <HOMESTATE>Illinois</HOMESTATE> 
    </PRESIDENT> 
    </LIST> 

如果從XML分別創建文件DTD架構,它不應該包含「[」]」你沒有界定黨和HOMESTATE你有錯誤的譯文定義屬性
。 PresidentsDTD.dtd:

<!ELEMENT LIST (PRESIDENT+)> 

<!ELEMENT PRESIDENT (NAME, TERM, PARTY, HOMESTATE)> 

<!ELEMENT NAME (FIRST, MIDDLE?, LAST)> 
<!ELEMENT FIRST (#PCDATA)> 
<!ELEMENT MIDDLE (#PCDATA)> 
<!ELEMENT LAST (#PCDATA)> 

<!ELEMENT TERM (TERMSTART, TERMEND, TERMLENGTH)> 
<!ELEMENT TERMSTART (#PCDATA)> 
<!ELEMENT TERMEND (#PCDATA)> 
<!ELEMENT TERMLENGTH (#PCDATA)> 

<!ELEMENT PARTY (#PCDATA)> 
<!ELEMENT HOMESTATE (#PCDATA)> 


<!ATTLIST PRESIDENT 
      id ID #REQUIRED 
      gender (male | female) #IMPLIED 
      name CDATA #IMPLIED> 
<!ATTLIST TERM 
      count CDATA #IMPLIED> 
<!ATTLIST TERMLENGTH 
      unit (months | years) #IMPLIED>