日期:2014-05-19  浏览次数:20551 次

DataGrid 绑定 xml 的问题
XmlDocument   dom   =   new   XmlDocument();
dom.LoadXml(usersxml);
dom.Save( "d:/userxml.xml ");
dom.RemoveAll();
DataSet   ds   =new   DataSet();
ds.ReadXml( "d:/userxml.xml ");
this.DataGrid1.DataSource   =   ds.Tables[0];
this.DataGrid1.DataBind();

什么都没读出来

其实只是想取得   一列就行     每个 <user> 里的 <param   name= "realname "   value= "陈立军 "   /> 这个

也换了种写法     可也没显示出   数据     求XDJM们帮帮忙看下~~~谢谢  


XmlNodeList     nodes   =   dom.SelectNodes( "orgUnit/user/param[@name= 'realname '] ");
if(nodes!=null)
{
  foreach   (XmlNode   node   in   nodes)
  {
    DataTable   dt   =   new   DataTable();
    dt.Columns.Add( "name ",Type.GetType( "System.String "));

    dt.Columns.Add(node.Attributes[ "realname "].Value);
    this.DataGrid1.DataSource=dt;
    this.DataGrid1.DataBind();
}


---------------------
上面的程序也   显示不出数据~~~

下面是我的XML格式及内容

<?xml   version= "1.0 "   encoding= "UTF-8 "?>
<orgUnit   id= "2 "   name= "办公室 ">
    <user>
        <param   name= "category "   value= " "   />
        <param   name= "createdate "   value= "2007-3-28 "   />
        <param   name= "email "   value= "clj@jsppd.gov.cn "   />
        <param   name= "mobile "   value= "1234567890 "   />
        <param   name= "orgid "   value= "2 "   />
        <param   name= "orgname "   value= " "   />
        <param   name= "otherway "   value= "1234567890 "   />
        <param   name= "password "   value= "666 "   />
        <param   name= "phone "   value= " "   />
        <param   name= "position "   value= "主任 "   />
        <param   name= "realname "   value= "陈立军 "   />
        <param   name= "registerdate "   value= "2007-3-28 "   />
        <param   name= "servicedate "   value= "2018-10-11 "   />
        <param   name= "status "   value= "N "   />
        <param   name= "type "   value= "01 "   />
        <param   name= "userdsc "   value= "陈立军 "   />
        <param   name= "userid "   value= "135 "   />
        <param   name= "username "   value= "c