XML未在Eclipse中使用外部DTD进行验证

时间:2014-07-07 13:35:53

标签: xml eclipse validation xslt dtd

当我尝试解析XML时,Eclipse一直在读我的Riot Act。它正确显示在XSL中的网页上,所以我只包含XML和DTD。这些错误并不完全有用,“内容类型SoftWares必须与SoftWare匹配”。如果我说得对,我的DTD声明一个子元素是SoftWare,而后者又有四个子元素和三个可选属性。右侧的XML Outline在Eclipse中看起来不错,但它每五秒钟就会抛出“NULL POINTER”错误。我不确定我的代码有什么问题。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE SoftWares SYSTEM "Software.dtd">
 <?xml-stylesheet type="text/xsl" href="Software.xsl"?>
<SoftWares>
    <SoftWare>
    <Name>Photoshop</Name>
    <OS>Linux,Mac,Windows</OS>
    <Price>$500</Price>
    <Category>PhotoEditing</Category>

    </SoftWare>
    <SoftWare>
        <Name>GIMP</Name>
        <OS>Linux,Mac,Windows</OS>
        <Price>$0</Price>
        <Category>PhotoEditing</Category>
        </SoftWare>
    <SoftWare>
    <Name>Final Cut Pro X</Name>
    <OS>Mac</OS>
    <Price>$299</Price>
    <Category>VideoEditing</Category>

    </SoftWare>
    <SoftWare OS="Mac,Windows" Price="$200" Category="WordProcessor">
    <Name>MicroSoft Word</Name>
    <OS>Mac, Windows</OS>
    <Price>$200</Price>
    <Category>WordProcessor</Category>

    </SoftWare>
    <SoftWare OS="Linux,Mac,Windows" Price="$0" Category="WordProcessor">
    <Name>LibreOffice</Name>
    <OS>Linux,Mac,Windows</OS>
    <Price>$0</Price>
    <Category>WordProcessor</Category>
    </SoftWare>
    <SoftWare OS="Linux,Mac,Windows" Price="$2900" Category="3dModeling">
    <Name>Cinema 4D</Name>
    <OS>Linux,Mac,Windows</OS>
    <Price>$2900</Price>
    <Category>3dModeling</Category>
    </SoftWare>
    <SoftWare OS="Linux,Mac,Windows" Price="$0" Category="3dModeling">
    <Name>Blender</Name>
    <OS>Linux,Mac,Windows</OS>
    <Price>$299</Price>
    <Category>3dModeling</Category>
    </SoftWare>
    <SoftWare OS="Mac" Price="$500" Category="MusicMaker">
    <Name>Logic Pro</Name>
    <OS>Mac</OS>
    <Price>$500</Price>
    <Category>MusicMaker</Category>
    </SoftWare>
    <SoftWare OS="Linux,Mac,Windows" Price="$500" Category="MusicMaker">
    <Name>Ableton Live</Name>
    <OS>Linux,Mac,Windows</OS>
    <Price>$500</Price>
    <Category>MusicMaker</Category>
    </SoftWare>
    <SoftWare OS="Linux,Mac,Windows" Price="$200" Category="MotionGraphics">
    <Name>After Effects</Name>
    <OS>Linux,Mac,Windows</OS>
    <Price>$200</Price>
    <Category>MotionGraphics</Category>
    </SoftWare>
    <SoftWare OS="Mac" Price="$79" Category="MotionGraphics">
    <Name>Motion</Name>
    <OS>Mac</OS>
    <Price>$79</Price>
    <Category>MotionGraphics</Category>
    </SoftWare>
    <SoftWare OS="Linux,Mac,Windows" Price="$79" Category="ProgrammingSoftware">
    <Name>Sublime Text</Name>
    <OS>Linux,Mac,Windows</OS>
    <Price>$79</Price>
    <Category>ProgrammingSoftware</Category>
    </SoftWare>
    <SoftWare OS="Linux,Mac,Windows" Price="$0" Category="ProgrammingSoftware">
    <Name>Eclipse</Name>
    <OS>Linux,Mac,Windows</OS>
    <Price>$0</Price>
    <Category>ProgrammingSoftware</Category>
    </SoftWare>
    <SoftWare OS="Linux" Price="$0" Category="ProgrammingSoftware">
    <Name>Geany</Name>
    <OS>Linux</OS>
    <Price>$0</Price>
    <Category>ProgrammingSoftware</Category>

    </SoftWare>
</SoftWares>

和DTD:

<!ELEMENT SoftWares (SoftWare)> 
<!ELEMENT SoftWare (Name,OS,Price,Category)>
<!ELEMENT Name (#PCDATA)>
<!ELEMENT OS (#PCDATA)>
<!ELEMENT Price (#PCDATA)>
<!ELEMENT Category (#PCDATA)>

<!ATTLIST SoftWare OS CDATA #IMPLIED> 
<!ATTLIST SoftWare Price CDATA #IMPLIED>
<!ATTLIST SoftWare Category CDATA #IMPLIED>

1 个答案:

答案 0 :(得分:1)

您的DTD说,软件允许一个单个孩子名为Software。