开发者

How to get this XmlAttribute

From the MusicBrainz REST service, I get the following xml:

<artist-list offset="0" count="59">
  <art开发者_Python百科ist type="Person" id="xxxxx" ext:score="100">
  ...

Using WCF and XmlSerializationFormat, I'm able to get the type and id attributes... but How do I get the "ext:score" one?

This works:

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

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

But this doesnt:

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

It produces a serialization exception. I've also tried just using "score", but it doesn't work.

Any help?


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.


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

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜