恩,你上面的那个文件不是一个符合 XML 格式的文件,好像不能加载

解决方案 »

  1.   

    可以加载,没问题,只是不能读出<a>的student
      

  2.   

    用innertext只能读出
    <b cccccc>
       </b>
       stu
       <b dddddd>
       </d>
       dent
    你的格式有问题
      

  3.   

    StreamReader sr = new StreamReader("test.txt");
    String str = sr.ReadToEnd();
    sr.Close();
    int index = 0;
    string res = "";
    while ((index = str.IndexOf("</",index+1)) > 0)
    {
    int start = str.IndexOf('>', index + 1);
    int end = str.IndexOf('<', start + 1);
    if (start > 0 && end > 0)
    {
    res += str.Substring(start + 1, end - start - 1).Trim('\n','\r',' ');
    }
    }
    Console.WriteLine(res);
      

  4.   

    修改一下:
    StreamReader sr = new StreamReader("test.txt");
    String str = sr.ReadToEnd();
    sr.Close();
    int start = 0;
    string res = "";
    while ((start = str.IndexOf('>', start+1)) > 0)
    {
    int end = str.IndexOf('<', start + 1);
    if (end > 0)
    {
    res += str.Substring(start + 1, end - start - 1).Trim('\n','\r',' ');
    }else{
    res += str.Substring(start + 1).Trim('\n','\r',' ');
    break;
    }
    start = end + 1;
    }
    Console.WriteLine(res);
      

  5.   

    你这个是XML么,根本不符合定义
      

  6.   

    上面还是有些问题,再修改了一下:
    StreamReader sr = new StreamReader("test.txt");
    String str = sr.ReadToEnd();
    sr.Close();
    int index = 0;
    string res = "";
    while ((index = str.IndexOf("</",index)) > 0)
    {
    int start = str.IndexOf('>', index + 1);
    int end = str.IndexOf('<', start + 1);
    if (start > 0 && end > 0)
    {
    res += str.Substring(start + 1, end - start - 1).Trim('\n','\r',' ');
    index = end;
    } else break;
    }
    Console.WriteLine(res);