2014-01-30 88 views
0

我们是xsd的新用户,我们尝试验证需要导入另一个xsd文件的xsd文件。 我们正在尝试从companyInfos.xsd导入employmentrecord.xsd。 这是我们正在处理的两个xsd文件。 employmentrecord.xsd导入时出现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%20'以%20JB/SampleParser/ID2208_hw1/XML/employmentrecord.xsd”。如果这是不正确的命名空间,则可能需要更改'ci:company'的前缀。 如果这是正确的名称空间,则应将相应的'导入'标记添加到'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> 

我们试图寻找在论坛上一个答案,但提出的解决方案似乎没有工作,文件总是有一些问题需要验证。

+0

只是一个猜测,但您是否需要将'ci:company'定义为'',因为您指的是已定义的类型? –

+0

我们发现了这个错误: org.xml.sax.SAXParseException; systemId:file:///Users/kevin/Dropbox/ID2208_shared%20with%20JB/SampleParser/ID2208_hw1/xml/employmentrecord.xsd; lineNumber:12; columnNumber:40; s4s-att-not-allowed:属性'typeref'不能出现在元素'element'中。 – Kevin

+0

不确定你的问题到底是什么,引用来自导入模式的元素在我们的案例中工作得很好。也许看看[这里的链接](http://www.w3schools.com/schema/el_element.asp) –

回答

0

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