2010-04-29 31 views
2

從MusicBrainz的REST服務,我得到以下XML:如何獲取XmlAttribute

<artist-list offset="0" count="59"> 
    <artist type="Person" id="xxxxx" ext:score="100"> 
    ... 

使用WCF和XmlSerializationFormat,我能夠得到的類型和ID屬性...但我如何獲得「ext:score」一個嗎?

這工作:

public class Artist 
    { 
    [XmlAttribute("id")] 
    public string ID { get; set; } 

    [XmlAttribute("type")] 
    public ArtistType Type { get; set; } 

但這並不:

[XmlAttribute("ext:score")] 
public string Score { get; set; } 

它產生一個序列化異常。我也嘗試過使用「分數」,但它不起作用。

任何幫助?

回答

3

該屬性爲,名稱爲「score」,位於由「ext」引用的名稱空間中,該名稱空間可能是xml名稱空間別名。

所以查找 「分機」 映射到(找了xmlns),並添加:

[XmlAttribute("score", Namespace="http://example.org/ext-9.1#")] 
public string Score { get; set; } 

編輯;發現它here;見xmlns:ext="http://example.org/ext-9.1#"。另請注意,主對象似乎在xmlns="http://musicbrainz.org/ns/mmd-1.0#"中,您可能需要在根/對象級別進行說明。

1

extscore屬性的命名空間。嘗試指定命名空間:

[XmlAttribute(AttributeName="score", Namespace="the ext namespace")]