我正在尝试将以下XML节点(实际上是RDF)反序列化为类。
<rdf:Description rdf:about="http://d.opencalais.com/genericHasher-1/dae360d4-25f1-34a7-9c70-d5f7e4cfe175">
<rdf:type rdf:resource="http://s.opencalais.com/1/type/em/e/Country"/>
<c:name>Egypt</c:name>
</rdf:Description>
[Serializable]
[XmlRoot(Namespace = "http://www.w3.org/1999/02/22-rdf-syntax-ns#", ElementName = "Description")]
public class BasicEntity
{
[XmlElement(Namespace = "http://s.opencalais.com/1/pred/", ElementName = "name")]
public string Name { get; set; }
[XmlAttribute("about", Namespace = "http://www.w3.org/1999/02/22-rdf-syntax-ns#")]
public string Uri { get; set; }
}
正确解析name元素但不解析about属性。我做错了什么?
答案 0 :(得分:6)
您需要指定该属性将是名称空间限定。
[Serializable]
[XmlRoot(Namespace = "http://www.w3.org/1999/02/22-rdf-syntax-ns#", ElementName = "Description")]
public class BasicEntity
{
[XmlElement(Namespace = "http://s.opencalais.com/1/pred/", ElementName = "name")]
public string Name { get; set; }
[XmlAttribute("about", Form=XmlSchemaForm.Qualified, Namespace = "http://www.w3.org/1999/02/22-rdf-syntax-ns#")]
public string Uri { get; set; }
}