导入时出现xsd验证错误

时间:2014-01-30 12:27:23

标签: java xml validation xsd

我们是xsd的新用户,我们尝试验证需要导入另一个的xsd文件。 我们正在尝试从companyInfos.xsd导入到employmentrecord.xsd。 这是我们正在处理的两个xsd文件。 employmentrecord.xsd

<?xml version="1.0" encoding="UTF-8"?>

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:ci="companyInfos.xsd"
    targetNamespace="er" 
    elementFormDefault="qualified">

  <xsd:import namespace="ci" schemaLocation="companyInfos.xsd" />
    <xsd:element name="employment">    
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element type="ci:company"/>
                <xsd:element name="position" type="xsd:string"/>
                <xsd:element name="duration" type="xsd:string"/>
                <xsd:element name="dateStart" type="xsd:date"/>
                <xsd:element name="current" type="xsd:booolean"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>

companyInfos.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            targetNamespace="ci" elementFormDefault="qualified">
    <xsd:element name="company">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="companyName" type="xsd:string"/>
                <xsd:element name="foundationDate" type="xsd:date"/>
                <xsd:element name="field" type="xsd:string"/>
                <xsd:element name="employeeCount" type="xsd:integer"/>
                <xsd:element name="logo" type="xsd:anyURI"/>
                <xsd:element name="description" type="xsd:string"/>
                <xsd:element name="httpLink" type="xsd:anyURI"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>               
</xsd:schema>

在尝试有效期时,我们在终端中收到以下错误: org.xml.sax.SAXParseException; systemId:file:///home/jiby/Dropbox/ID2208_shared%20with%20JB/SampleParser/ID2208_hw1/xml/employmentrecord.xsd; 检测到'ci:company'位于命名空间'companyInfos.xsd'中,但来自此命名空间的组件无法从架构文档'file:/// home / jiby / Dropbox / ID2208_shared%20with%20JB / SampleParser / ID2208_hw1引用/xml/employmentrecord.xsd”。如果这是不正确的命名空间,则可能需要更改'ci:company'的前缀。 如果这是正确的命名空间,则应将相应的'import'标记添加到'file:///home/jiby/Dropbox/ID2208_shared%20with%20JB/SampleParser/ID2208_hw1/xml/employmentrecord.xsd'。

(我不知道它是否有用,但这里有两个xml文件)

<?xml version="1.0" encoding="UTF-8"?>
<employment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="er"
            xmlns:ci="companyInfos.xsd"
       >
     <ci:company>
            <companyName>
                Google
            </companyName>
            <foundationDate>
                1995-09-15
            </foundationDate>
            <field>
                Search engine
            </field>
            <employeeCount>
                40000
            </employeeCount>
            <logo>
                http://static3.wikia.nocookie.net/__cb20100520131748/logopedia/images/5/5c/Google_logo.png
            </logo>
            <description>
                Google is an American multinational corporation specializing in Internet-related services and products. These include search, cloud computing, software, and online advertising technologies
            </description>
    </ci:company>
    <position>Chief Finantial Opportunist</position>
    <duration>1 year</duration>
    <dateStart>2012-01-01</dateStart>
    <current>false</current>
</employment>


<?xml version="1.0" encoding="UTF-8"?>
<company  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns="ci">
    <companyName>
        Google
    </companyName>
    <foundationDate>
        1995-09-15
    </foundationDate>
    <field>
        Search engine
    </field>
    <employeeCount>
        40000
    </employeeCount>
    <logo>
        http://static3.wikia.nocookie.net/__cb20100520131748/logopedia/images/5/5c/Google_logo.png
    </logo>
    <description>
        Google is an American multinational corporation specializing in Internet-related services and products. These include search, cloud computing, software, and online advertising technologies
    </description>
    <httpLink>http://google.com</httpLink>
</company>

我们试图在论坛上寻找答案,但建议的解决方案似乎不起作用,该文件总是有一些问题需要验证。

1 个答案:

答案 0 :(得分:0)

我认为您在名称空间前缀和名称空间URI之间感到困惑。 xs:importSchema的namespace属性和xs:schema的targetNamespace属性都应该是URI,它们应该匹配。您还应该将前缀绑定到此URI,并在对导入的模式名称空间中的名称的任何引用中使用此前缀。