在线等一段XML解析代码 代码要自己写,可以给你思路:用循环遍历 XmlElement.Name == " classname " ,GetVaule() 获的值,再遍历 XmlElement.Name == "teacher" ,GetVaule(),。获得值了,存入数据库了就不用我说了吧。举一反三,自己再把代码写完,才能体会到。这个XML格式算是最简单的一种了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你这个字符串不是标准的你得先构造成标准字符串然后用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;................ 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>标签,不然会报错有多个rootxml里有些拼写错误,englisg的g classInfo的I 如何在winform窗体上弄一个横向的动态滚动 提示 没有什么基础,学习C#应该怎么进行? 考考你算法 C 十进制int和double转换成二进制 面试题,大家来练练手 有关静态类的问题?? StreamWriter 关闭怎么还报错,急!哪位能帮帮我,再线等 C#设置自定义标题栏怎么办哇 想得到List<>的元素增加的事件,怎么最简单? 复制QQ对话框内容 到 richTextBox ,不能复制图片问题 在together designer 2005 中怎么样用C#代码生成类图?求高手指点 關於更新問題
你得先构造成标准字符串
然后用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;
................
"张三 </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