当前位置: 代码迷 >> Web Service >> (方法返回xmlnode类型数据)xml数据中含有三个表信息,怎么读取并分别显示到三个表中
  详细解决方案

(方法返回xmlnode类型数据)xml数据中含有三个表信息,怎么读取并分别显示到三个表中

热度:245   发布时间:2012-12-15 15:16:03.0
(方法返回xmlnode类型数据)xml数据中含有三个表信息,如何读取并分别显示到三个表中

<Student>
   <Student Sname="李四 " Sage="15 " Ssex="女">
     <初中成绩>
     <Course>化学</Course>
     <Score>77</Score>
     <Course>地理</Course>
     <Score>78</Score>
     <Course>物理</Course>
     <Score>88</Score>
     </初中成绩>
     <高中成绩>
     <Course>语文</Course>
     <Score>90</Score>
     <Course>数学</Course>
     <Score>99</Score>
     <Course>英语</Course>
     <Score>88</Score>
     </高中成绩>
   </Student>[/align]<Student Sname="王五" Sage="16" Ssex="男">
以下同样的格式
     

------最佳解决方案--------------------
dt.Rows[i][j]= root.ChildNodes.ChildNodes[j].InnerText;
------其他解决方案--------------------

string str = File.ReadAllText("D:\\lx.xml", Encoding.Default);
            var ary = Regex.Matches(str, @"<ttt(?=.*?Sname=""(?<name>[^""]+)"")(?=.*?Sage=""(?<age>[^""]+)"")(?=.*?Ssex=""(?<sex>[^""]+)"").*?>(((?!</ttt>)[\s\S])*?(?<score><(?<xl>\w*?)成绩>[\s\S]*?</\w.*?成绩>))*[\s\S]*?</ttt>").Cast<Match>().Select(t => new
            {
                name = t.Groups["name"].Value,
                age = t.Groups["age"].Value,
                sex = t.Groups["sex"].Value,
                xueli = t.Groups["xl"].Captures.Cast<Capture>().Select(tt => tt.Value).ToArray(),
                score = t.Groups["score"].Captures.Cast<Capture>().Select(x => Regex.Matches(x.Value, @"<Course>(\w+)</Course>\s*<Score>(\d+(\.\d+)?)</Score>").Cast<Match>().Select(tt => new { 科目 = tt.Groups[1].Value, 成绩 = tt.Groups[2].Value }).ToArray()).ToArray()
            }).ToArray();

------其他解决方案--------------------
以上是方法返回的xml格式数据格式
------其他解决方案--------------------
这边都没人啊


<Student>   
  <Student Sname="李四 " Sage="15 " Ssex="女">   
    <初中成绩>     
      <Course>化学</Course>    
      <Score>77</Score>    
  相关解决方案