题
从Musicbrainz休息服务中,我得到以下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; }
它产生序列化例外。我也尝试使用“得分”,但它不起作用。
有帮助吗?
解决方案
属性是 命名 “得分”,并且位于“ ext”引用的命名空间中,大概是XML名称空间别名。
因此,查找“ ext”地图的内容(查找XMLNS),然后添加:
[XmlAttribute("score", Namespace="http://example.org/ext-9.1#")]
public string Score { get; set; }
编辑;找到了 这里;看 xmlns:ext="http://example.org/ext-9.1#"
. 。另请注意,主要对象似乎在 xmlns="http://musicbrainz.org/ns/mmd-1.0#"
您可能需要在root/对象级别上进行解释。
其他提示
这 ext
是名称空间 score
属性。尝试指定名称空间:
[XmlAttribute(AttributeName="score", Namespace="the ext namespace")]
不隶属于 StackOverflow