如何获取这个XmlAttribute
从 MusicBrainz REST 服务中,我得到以下 xml:
<artist-list offset="0" count="59">
<artist type="Person" id="xxxxx" ext:score="100">
...
使用 WCF 和 XmlSerializationFormat,我能够获取 type 和 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; }
它会产生序列化异常。我也尝试过只使用“分数”,但它不起作用。
有什么帮助吗?
From the MusicBrainz REST service, I get the following xml:
<artist-list offset="0" count="59">
<artist 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该属性命名为“score”,位于“ext”引用的命名空间中,该命名空间可能是一个 xml 命名空间别名。
因此,找到“ext”映射到的内容(查找 xmlns),然后添加:
编辑;在此处找到了它;请参阅
xmlns:ext="http://example.org/ext-9.1#"
。另请注意,主要对象似乎位于xmlns="http://musicbrainz.org/ns/mmd-1.0#"
中,您可能需要在根/对象级别进行说明。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:
Edit; found it here; see
xmlns:ext="http://example.org/ext-9.1#"
. Also note that the main objects seem to be inxmlns="http://musicbrainz.org/ns/mmd-1.0#"
which you may need to account for at the root/object level.ext
是score
属性的命名空间。尝试指定命名空间:The
ext
is the namespace of thescore
attribute. Try specifying the namespace: