日期:2014-05-18 浏览次数:20853 次
List<string> PropertyValue= new List<string>(); string xmlstr = "<?xml version=\"1.0\"?>"+ "<Propertys Name =\"myName\">" + "<Data Value=\"11\"/>" + "<Data Value=\"22\"/>" + "<Data Value=\"33\"/>" + "</Propertys>"; XmlDocument xd = new XmlDocument(); xd.LoadXml(xmlstr); XmlNodeList xl = xd.GetElementsByTagName("Data"); for (int i = 0; i < xl.Count; i++) { PropertyValue.Add(xl[i].Attributes["Value"].Value); }
------解决方案--------------------
List<string> value_list = new List<string>(); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(@"C:\Documents and Settings\Administrator\桌面\Test.txt"); foreach (XmlNode xn in xmlDoc.SelectNodes("//Propertys/Data")) { value_list.Add(xn.Attributes["Value"].Value); } /* * [0] "11" string [1] "22" string [2] "33" string */
------解决方案--------------------
<?xml version="1.0" encoding="utf-8" ?> <Propertys Name ="myName"> <Data Value="11"/> <Data Value="22"/> <Data Value="33"/> </Propertys> 以下是读取代码: using System.Xml.Linq; using System.Xml; using System.Text; StringBuilder sb = new StringBuilder(); string[] PropertyValue; XmlDocument xml = new XmlDocument(); xml.Load(Server.MapPath("test.xml")); XmlNodeList xn = xml.SelectNodes("Propertys/Data"); foreach (XmlNode xn1 in xn) { sb.Append(xn1.Attributes["Value"].Value+","); } PropertyValue = sb.ToString().TrimEnd(',').Split(','); foreach (string s in PropertyValue) { Response.Write(s+"</br>"); }
------解决方案--------------------