using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace testDataXml { class Program { static void Main(string[] args) { Program pg = new Program(); pg.test2(); } /// <summary> /// 循环一次性提取所有的数据(记事本也可以) /// </summary> void test1() { string tempString = ""; string path = @"E:MyWorkasp.net estxmldatafr003465.xml"; string resettempString = ""; using (StreamReader sr = new StreamReader(path)) { tempString = sr.ReadToEnd(); if (tempString.Length > 0) { resettempString = tempString.Replace(tempString.Substring(0, 1), "<"); } } } /// <summary> /// 循环提取xml每一行记录(记事本也可以) /// </summary> void test2() { string tempString = ""; string path = @"E:MyWorkasp.net estxmldatafr003465.xml"; using (StreamReader sr = new StreamReader(path)) { while (sr.Peek() >= 0) { tempString = sr.ReadLine(); if (tempString == "hello word") { //把接下来获取的几行保存起来 } } } } } }
test1();方法的结果
test2();方法的结果