我想在下面的示例中反序列化。
我可以获得大多数attritubes,但在ViewElementDetail中,我不知道如何获取它(查询)。
using (var stream = new FileStream(file, FileMode.Open))
{
var serializer = new System.Xml.Serialization.XmlSerializer(typeof(List<ViewElement>));
var aa = (List<ViewElement>)serializer.Deserialize(stream);
}
public class ViewElement
{
[XmlAttribute]
public string ViewName { get; set; }
[XmlAttribute]
public string ColumnName { get; set; }
[XmlAttribute]
public string Description { get; set; }
[XmlElement]
public List<ViewElementDetail> ViewElementDetail { get; set; }
}
public class ViewElementDetail
{
[XmlAttribute]
public string Type { get; set; }
/// <summary>I don't know how to get this value</summary>
[XmlAttribute]
public string Query { get; set; }
}
答案 0 :(得分:1)
使用[XmlText]
属性标记应从元素textContent
反序列化的属性:
class ViewElementDetial {
[XmlAttribute]
public string Type { get; set; }
[XmlText]
public String Query { get; set; }
}