2010-03-11 50 views
1

在下面的模式中,行<xs:element type="cmn:AddressType" name="ResidentialAddress" minOccurs="1" maxOccurs="1" />給出了錯誤Type 'http://company.com/Common:AddressType' is not declared爲什麼我可以從xsd模式導入此類型?

有誰知道爲什麼?它在Visual Studio 2008編輯器中顯示,並且如果我嘗試使用XDocument驗證XML文件。

架構Student.xsd:

<?xml version="1.0" encoding="utf-8"?> 
<xs:schema id="Student" 
    xmlns:cmn="http://company.com/Common" 
    targetNamespace="http://company.com/Student" 
    elementFormDefault="qualified" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
> 

    <xs:import id="cmn" schemaLocation="Address.xsd" 
      namespace="http://company.com/Common" /> 

    <xs:element name="Student" nillable="false"> 
    <xs:complexType> 
     <xs:sequence minOccurs="1"> 
     <xs:element name="Id" type="xs:integer" nillable="false" minOccurs="1" maxOccurs="1" /> 
     <xs:element type="cmn:AddressType" name="ResidentialAddress" minOccurs="1" maxOccurs="1" /> 
     </xs:sequence> 
    </xs:complexType> 

    </xs:element> 
</xs:schema> 

架構Address.xsd:

<xs:schema 
    targetNamespace="http://company.com/Common" 
    elementFormDefault="qualified" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
> 
    <xs:element name="AddressType"> 
    <xs:complexType> 
     <xs:sequence> 
     <xs:element name="Line1" minOccurs="1" maxOccurs="1" /> 
     <xs:element name="Line2" minOccurs="0" maxOccurs="1" /> 
     </xs:sequence> 
    </xs:complexType> 
    </xs:element> 
</xs:schema> 
+0

問題應該是「爲什麼我不能」而不是「爲什麼我」。 – 2010-03-11 15:16:25

回答

2

這是因爲你實際上聲明地址類型爲元素,不是。如果你想在你的主架構使用它作爲一個元素,可以使用:

<xs:element ref="cmn:AddressType" minOccurs="1" maxOccurs="1" /> 

如果你希望它是一個類型,然後擺脫你的地址架構中的元素聲明的,放在<xs:complexType name="AddressType">代替。

相關問題