2014-01-30 132 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,並在對導入的模式名稱空間中的名稱進行任何引用時使用此前綴。