xml:
<DocumentElement> <cityconfig> <city>阿坝州</city> <jc>abazhou</jc> <nbf>s</nbf> <viewname>view_news_title_index_abazhou</viewname> </cityconfig> <cityconfig> <city>阿克苏</city> <jc>akesu</jc> <nbf>s</nbf> <viewname>view_news_title_index_akesu</viewname> </cityconfig> <cityconfig> <city>安达</city> <jc>anda</jc> <nbf>n</nbf> <viewname>view_news_title_index_anda</viewname> </cityconfig> </DocumentElement>实现方式:
string path = "./XMLFile1.xml"; ; string content = GetContent(path); StringReader txtReader = new StringReader(content); XmlTextReader xmlReader = new XmlTextReader(txtReader); DataSet ds = new DataSet(); ds.readxml(xmlReader); string m = ""; foreach (DataColumn c in ds.Tables[0].Columns) { m += c.ColumnName + "-"; } return;// ds.Tables[0];
调用方法:
public static String GetContent(String vFileName) { StreamReader reader = new StreamReader(vFileName); StringBuilder result = new StringBuilder(); string line = reader.ReadLine(); while (line != null) { result.AppendLine(line); line = reader.ReadLine(); } reader.Close(); return result.ToString(); }