首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web Service >

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

2012-12-15 
(方法返回xmlnode类型数据)xml数据中含有三个表信息,如何读取并分别显示到三个表中StudentStudent Snam

(方法返回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>    


    </初中成绩>    
 </Student>
<Student Sname="王五" Sage="16" Ssex="男">
以下同理


我是想用以下代码将初中成绩都循环到一个表中,可是无法赋值,该怎么改呢


 for (int i = 0; i < root.ChildNodes.Count; i++)
            {
                for (int j = 0; j < root.ChildNodes.ChildNodes.Count; j++)
                {
                    dt.Rows[i][j].ToString() = Convert.ToString(root.ChildNodes.ChildNodes[j].InnerText);
                }
            }

[其他解释]
还有就是当有三个同级子节点呢,又咋样将初中跟高中成绩循环到对应的初中表跟高中表中呢


<Student>   
  <Student Sname="李四 " Sage="15 " Ssex="女">   
    <初中成绩>     
      <Course>化学</Course>    
      <Score>77</Score>    
    </初中成绩>    
    <高中成绩>     
      <Course>语文</Course>   
      <Score>90</Score>    
    </高中成绩>  
 </Student>
<Student Sname="王五" Sage="16" Ssex="男">

热点排行