您的位置:首页 > 其它

读取xml文件中的数据示例

2015-12-09 17:17 281 查看
读取xml文件中的数据示例

public class WindowTypeMapItem
{
[XmlAttribute(AttributeName = "AssemblyName")]
public string AssemblyName { get; set; }

[XmlAttribute(AttributeName = "TypeName")]
public string TypeName { get; set; }

[XmlAttribute(AttributeName = "TypeKey")]
public string Key { get; set; }

[XmlAttribute(AttributeName = "Cacheable")]
public bool IsCacheable { get; set; }
}


XmlDocument document = new XmlDocument();
document.Load(fileName);
XmlNodeList nodes = document.DocumentElement.SelectNodes("./WindowTypeMapItem");
foreach (XmlNode node in nodes)
{
string assemblyName = node.Attributes["AssemblyName"].Value;
string typeName = node.Attributes["TypeName"].Value;
string typeKey = node.Attributes["TypeKey"].Value;
bool cacheable = Convert.ToBoolean(node.Attributes["Cacheable"].Value);
windowTypeMapItems.Add(new WindowTypeMapItem() { AssemblyName = assemblyName, IsCacheable = cacheable, Key = typeKey, TypeName = typeName });
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: