读写XML字符串信息
1 using (var sw = new StringWriter()) 2 { 3 var xtw = new XmlTextWriter(sw); 4 //根节点 5 xtw.WriteStartElement("Test"); 6 //内容 7 xtw.WriteAttributeString("Name", "内容"); 8 xtw.WriteEndElement(); 9 string strInString = sw.ToString(); 10 }
1 string strInString = ""; 2 var xx = new XmlDocument(); 3 xx.LoadXml(strInString);//加载xml 4 var xxList = xx.GetElementsByTagName("Test"); //取得节点名为row的XmlNode集合 5 foreach (XmlNode xxNode in xxList) 6 { 7 //col节点name属性值 8 if (xxNode.Attributes != null) 9 { 10 xxNode.Attributes["Name"].Value; 11 } 12 }