C# XML反序列化问题(具有命名空间的属性)

C# XML反序列化问题(具有命名空间的属性),c#,xml,rdf,xml-deserialization,C#,Xml,Rdf,Xml Deserialization,我试图将下面的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:

我试图将下面的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; }
    }

埃及
[可序列化]
[XmlRoot(命名空间=”http://www.w3.org/1999/02/22-rdf-syntax-ns#“,ElementName=“Description”)]
公共阶级基本性
{
[XmlElement(命名空间=”http://s.opencalais.com/1/pred/“,ElementName=“name”)]
公共字符串名称{get;set;}
[XmlAttribute(“关于”,命名空间=”http://www.w3.org/1999/02/22-rdf-syntax-ns#")]
公共字符串Uri{get;set;}
}

name元素已正确解析,但about属性未正确解析。我做错了什么?

您需要指定该属性将被命名空间限定

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

我对这一领域一无所知,但奇怪的是,XML中有rdf:about=“”,而类中有xmltattribute(“about”,Namespace=”。这绝对正确吗?是的。rdf:about属性的内容是我想要的,并且名称空间与代码中显示的一样。非常有用,谢谢。但它应该是:[xmltattribute(“关于“,Namespace=”“,Form=XmlSchemaForm.Qualified)]公共字符串Uri{get;set;}