2

从 MusicBrainz REST 服务,我得到以下 xml:

<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; }

它产生一个序列化异常。我也试过只使用“分数”,但它不起作用。

有什么帮助吗?

4

2 回答 2

3

The attribute is named "score", and is in the namespace referenced by "ext", which is presumably an xml namespace alias.

So find what "ext" maps to (look for an xmlns), and add:

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

Edit; found it here; see xmlns:ext="http://example.org/ext-9.1#". Also note that the main objects seem to be in xmlns="http://musicbrainz.org/ns/mmd-1.0#" which you may need to account for at the root/object level.

于 2010-04-29T10:16:34.487 回答
1

The ext is the namespace of the score attribute. Try specifying the namespace:

[XmlAttribute(AttributeName="score", Namespace="the ext namespace")]
于 2010-04-29T10:19:55.163 回答