代码要自己写,可以给你思路:用循环遍历 XmlElement.Name == " classname " ,GetVaule() 获的值,再遍历 XmlElement.Name == "teacher" ,GetVaule(),。获得值了,存入数据库了就不用我说了吧。举一反三,自己再把代码写完,才能体会到。这个XML格式算是最简单的一种了

解决方案 »

  1.   

    你这个字符串不是标准的
    你得先构造成标准字符串
    然后用XPath实现string   strXML=" <classInfo> <classname> 一三班 </classname> <teacher> 刘洪 </teacher> </classinfo> <score> <studname> 张三 </studname> <chinese> 95 </chinese> <english> 85 </englisg> <math> 90 </math> </score> <score> <studname> 李四 </studname> <chinese> 95 </chinese> <english> 85 </englisg> <math> 90 </math> </score> "; 
    strXML = "<Root>" + strXML + "</Root>";XmlDocument doc = new XmlDocument();
    doc.LoadXml(strXML);
    string tclass = doc.SelectSingleNode("/Root/classInfo/classname").InnerText;
    string tescher = doc.SelectSingleNode("/Root/classInfo/teacher").InnerText;
    ................
      

  2.   

    string strXML = "<root> <classinfo> <classname> 一三班 </classname> <teacher> 刘洪 </teacher> </classinfo> <score> <studname> "+
                    "张三 </studname> <chinese> 95 </chinese> <english> 85 </english> <math> 90 </math> </score> <score> " +
                    "<studname>李四 </studname> <chinese> 95 </chinese> <english> 85 </english> <math> 90 </math> </score> </root>";
    XmlDocument doc = new XmlDocument();
    doc.LoadXml(strXML);
    string strClass = doc.SelectSingleNode("/root/classinfo/classname").InnerText.Trim();
    string strTeacher = doc.SelectSingleNode("/root/classinfo/teacher").InnerText.Trim();textBox1.Text += strClass + " ||| " + strTeacher;以上代码编译通过
    需要在外面再加一个<root></root>标签,不然会报错有多个root
    xml里有些拼写错误,englisg的g  classInfo的I