2015-12-10 99 views
0

錯誤驗證錯誤XSD架構是:與驗證過程中發生的嵌套複雜類型

The element 'Details' in namespace 
'<-namespace->' has incomplete content. List of possible elements expected: 
'PersonAddress' in namespace '<-namespace->'. 

架構如下(大部分除去,可讀性):

<xs:complexType name="Person"> 
    <xs:all>    
     <xs:element minOccurs="1" maxOccurs="1" name="Details" type="PersonDetails" /> 
    </xs:all> 
</xs:complexType> 

<xs:complexType name="PersonDetails"> 
    <xs:all>   
     <xs:element minOccurs="1" maxOccurs="1" nillable="true" name="PersonAddress" type="PersonAddress" /> 
    </xs:all> 
</xs:complexType> 

<xs:complexType name="PersonAddress"> 
    <xs:all> 
      <xs:element minOccurs="1" maxOccurs="1" name="Street" type="xs:string" /> 
      <xs:element minOccurs="1" maxOccurs="1" nillable="true" name="ZipCode" type="xs:int" />   
    </xs:all> 
</xs:complexType> 

當我序列到XML使用架構和我的DTO:s我映射PersonAddress爲null或反映'PersonAddress'的對象

我除了我的最終xml結果如:

</PersonDetails> 
    <PersonAddress xsi:nil="true" /> 
</PersonDetails> 

相反,我在驗證xsd模式的過程中遇到了一個錯誤,正如本文中首先解釋的那樣。


它工作正常,當我在PersonDetails上PersonAddress設置的minOccurs爲零:

<xs:element minOccurs="0" maxOccurs="1" nillable="true" name="PersonAddress" type="PersonAddress" /> 

但問題是,當我映射對象設置爲「空」的元素不顯示在所有。它不存在。

任何我在xsd模式中遺漏的東西?

+0

你的問題看起來錯誤或不完整 - 你的錯誤信息是指'Details'元素,但你的架構和XML不顯示任何'詳細元素。這應該是一個'PersonDetails'元素嗎? –

+1

@MattJones Details元素是Person中xs:元素的名稱。細節是PersonDetails –

+0

的類型啊是的,你是對的。我沒有在腦海中解析這一點! –

回答

0

好的,所以我在DTO中犯了一個錯誤。

現在是啓動和這種變化的工作:

[XmlElement(IsNullable = true)] 
public PersonAddress PersonAddress { get; set; } 

忘記給ISNULLABLE標籤添加到DTO屬性。

自我提醒,張貼堆棧溢出之前檢查mindfucks ..