标签:
一:把xml文件做成串
string content = @"<xml> <name>123</name> <class><time>2015-1-1</time></class> <class><time>2015-1-1</time></class> <class><time>2015-1-1</time></class> <class><time>2015-1-1</time></class> </xml> "; XmlDocument doc = new XmlDocument(); doc.LoadXml(content); XmlNodeList list = doc.GetElementsByTagName("class"); foreach (XmlNode item in list) { var aa = item.InnerText; }
二:读取文件夹中的xml 文件
// xmlFileName 路径
if (!File.Exists(xmlFileName)) return null; //加载XML var xmldoc = new XmlDocument(); xmldoc.Load(xmlFileName); //获取根目录 var root = xmldoc.DocumentElement; if (root == null) return null; var nodeCount = root.ChildNodes.Count; if (nodeCount <= 0) return null; var j = 0; list = new List<RecordModel>(0); //取值 for (var i = nodeCount - 1; i >= 0; i--) { if (count != -1) { j++; if (j > count) { break; } } var node = root.ChildNodes[i]; if (node == null) continue; var recordModel = new RecordModel { SendUserId = node["SendUserId"].InnerText, Message = node["Message"].InnerText, Time = node["Time"].InnerText, }; var domainnode = node["Domain"]; if (domainnode != null) { recordModel.Domain = domainnode.InnerText; } var urlAddressnode = node["UrlAddress"]; if (urlAddressnode != null) { recordModel.Domain = urlAddressnode.InnerText; } list.Add(recordModel); } return list;
标签:
原文地址:http://www.cnblogs.com/xiaoyaodijun/p/4757940.html