[英]Problem with Serialization/Deserialization an XML containing CDATA attribute
[英]XML deserialization problem (attribute with a namespace)
我正在尝试将以下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属性未正确解析。 我究竟做错了什么?
您需要指定该属性将是名称空间限定的。
[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; }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.