2010-12-02 27 views
1

中的XML如下所示:XmlSerializer的和XmlArrayItem

<Publisher sequence="1" primaryIndicator="Yes"> 
    <PublisherID idType="Shortname">ysc</PublisherID> 
    <PublisherID idType="xy" encrypted="VlsC1V9K23Leo1BAOk6nxxROZAPKSAny" library="http://xys.abc.com">21503</PublisherID> 
    <PublisherName nameType="Legal">xys legal name</PublisherName> 
</Publisher> 

我的類被映射爲:

type PublisherId() = 
    [<DefaultValue>] val mutable _idType: string ; 
    [<DefaultValue>] val mutable _encrypted: string ; 
    [<DefaultValue>] val mutable _library: string ; 
    [<DefaultValue>] val mutable _value: string ; 

    [<XmlAttribute>] member this.idType with get() = this._idType and set(v) = this._idType <- v 
    [<XmlAttribute>] member this.encrypted with get() = this._encrypted and set(v) = this._encrypted <- v 
    [<XmlAttribute>] member this.library with get() = this._library and set(v) = this._library <- v 
    [<XmlTextAttribute>] member this.value with get() = this._value and set(v) = this._value <- v 

type Publisher() as this = 
    [<DefaultValue>] val mutable _sequence : int 
    [<DefaultValue>] val mutable _primaryIndicator: string ; 
    [<DefaultValue>] val mutable _publisherIds : List<PublisherId> 

    do 
     this._publisherIds <- new List<PublisherId>(); 

    [<XmlAttribute>] member this.sequence with get() = this._sequence and set(v) = this._sequence <- v 
    [<XmlAttribute>] member this.primaryIndicator with get() = this._primaryIndicator and set(v) = this._primaryIndicator <- v 

    [<XmlArrayAttribute>] 
    [<XmlArrayItem(typeof<PublisherId>, ElementName = "PublisherID")>] 
    member this.PublisherID with get() = this._publisherIds and set(v) = this._publisherIds <- v 

,我還修改了成員問題上elemetn屬性:

[<XmlArrayItem(typeof<PublisherId>, ElementName = "PublisherID")>] 
    member this.PublisherID with get() = this._publisherIds and set(v) = this._publisherIds <- v 

問題是,它沒有填充_publisherIds字段。我試圖切換到一個數組,這也沒有幫助。設置者中的斷點永遠不會受到影響,所以我認爲註釋有問題。

我已經成功與類似的結構:

<Publisher sequence="1" primaryIndicator="Yes"> 
    <PublisherIDs> 
    <PublisherID idType="Shortname">ysc</PublisherID> 
    <PublisherID idType="xy" encrypted="VlsC1V9K23Leo1BAOk6nxxROZAPKSAny" library="http://xys.abc.com">21503</PublisherID> 
    </PublisherIDs> 
    <PublisherName nameType="Legal">xys legal name</PublisherName> 
</Publisher> 
使用類似的屬性(儘管C#)

,但是改變XML結構沒有安選項 - 因爲這是從供應商正在添加。

注:我標記爲C#以及該組可能能夠幫助註釋。請刪除我的appologies,如果這是一個不適當的標籤。

謝謝

回答