日期:2009-07-15  浏览次数:20490 次

//查询XML(C#)
DataSet strXML=new DataSet();
string path="XMLFile1.XML";
strXML.ReadXML(Server.MapPath(path));


this.TextBox1.Text=strXML.Tables[0].Rows[0]["sqlchaxun"].ToString();
this.TextBox2.Text=strXML.Tables[0].Rows[1]["sqlchaxun"].ToString();
//XMLFile1.XML
<?XML version="1.0" encoding="utf-8" ?>
<sql>
 <sqlyhtj>
  <sqlchaxun>中华人民共和国</sqlchaxun>
 </sqlyhtj>
 <sqlyhtj>
  <sqlchaxun>中华人民共和国1</sqlchaxun>
 </sqlyhtj>
</sql>

//修改XML(c#)
System.XML.XMLDocument str1=new System.XML.XMLDocument();
string path="XMLFile1.XML";
str1.Load(Server.MapPath(path));
System.XML.XMLNode str2=str1.SelectSingleNode("/sql/sqlyhtj/sqlchaxun");
str2.InnerText=this.TextBox1.Text.Trim();
str1.Save(Server.MapPath(path));
//XMLFile1.XML
<?XML version="1.0" encoding="utf-8"?>
<sql>
  <sqlyhtj>
    <sqlchaxun>yaomingchensss</sqlchaxun>
  </sqlyhtj>
</sql>
//读XML
//XML
<?XML version="1.0" encoding="utf-8"?>
<yhgl>
  <liebiaoxiang>
    <ACTIDNAME>帐号</ACTIDNAME>
    <ACTID>True</ACTID>
    <USRNAMENAME>用户名称</USRNAMENAME>
    <USRNAME>True</USRNAME>
  </liebiaoxiang>
</yhgl>

this.ACTID.Text=dsread.Tables[0].Rows[0]["ACTIDNAME"].ToString();
this.ACTID.Checked=bool.Parse(dsread.Tables[0].Rows[0]["ACTID"].ToString());
this.USRNAME.Text=dsread.Tables[0].Rows[0]["USRNAMENAME"].ToString();
this.USRNAME.Checked=bool.Parse(dsread.Tables[0].Rows[0]["USRNAME"].ToString());

for(int i=1;i<=46;i++)
{
BoundColumn columni=new BoundColumn();
columni.HeaderText=dsXML.Tables[0].Rows[i]["chinese"].ToString();
columni.DataField=dsXML.Tables[0].Rows[i]["english"].ToString();
columni.HeaderStyle.Wrap=false;
columni.ItemStyle.Wrap=false;  

columni.Visible=bool.Parse(dsyincang.Tables[0].Rows[0][dsXML.Tables[0].Rows[i]["english"].ToString()].ToString());
//列标题居中显示
columni.HeaderStyle.HorizontalAlign=HorizontalAlign.Center;
//列内容居左显示
columni.ItemStyle.HorizontalAlign=HorizontalAlign.Left;
this.DataGrid1.Columns.Add(coli);
}