²Ù×÷XML£¬¶ÔXMLµÄÔöɾ¸Ä²é²Ù×÷¡£asp.net C#
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Xml;
namespace jiufen.Web.code
{
public class OperatingXML
{
XmlDocument xmlDoc = new XmlDocument();
//load xml file
private void LoadXml()
{
xmlDoc = new XmlDocument();
xmlDoc.Load(HttpContext.Current.Server.MapPath("xml/User.xml"));//xmlµÄ¸ùĿ¼
}
//Ìí¼Ó½Úµã
public void AddElement()
{
LoadXml();
XmlNode xmldocSelect = xmlDoc.SelectSingleNode("user");
XmlElement el = xmlDoc.CreateElement("person"); //Ìí¼Óperson½Úµã
el.SetAttribute("name", "ÖܽÜÂ×"); //Ìí¼Óperson½ÚµãµÄÊôÐÔ"name"
el.SetAttribute("sex", "ÄÐ"); //Ìí¼Óperson½ÚµãµÄÊôÐÔ "sex"
el.SetAttribute("age", "52"); //Ìí¼Óperson½ÚµãµÄÊôÐÔ "age"
XmlElement xesub1 = xmlDoc.CreateElement("pass"); //Ìí¼Óperson½ÚµãµÄÀïµÄ½Úµã
xesub1.InnerText = "22";//ÉèÖÃÎı¾½Úµã
el.AppendChild(xesub1);
XmlElement xesub2 = xmlDoc.CreateElement("Address");
xesub2.InnerText = "À¥Ã÷";//ÉèÖÃÎı¾½Úµã
el.AppendChild(xesub2);
xmldocSelect.AppendChild(el);
xmlDoc.Save(HttpContext.Current.Server.MapPath("xml/User.xml"));
}
//Ð޸Ľڵã
public void UpdateElement()
{
LoadXml();
XmlNodeList nodeList = xmlDoc.SelectSingleNode("user").ChildNodes;//»ñÈ¡bookstore½ÚµãµÄËùÓÐ×Ó½Úµã
foreach (XmlNode xn in nodeList)//±éÀúËùÓÐ×Ó½Úµã
{
XmlElement xe = (XmlElement)xn;//½«×Ó½ÚµãÀàÐÍת»»ÎªXmlElementÀàÐÍ
if (xe.GetAttribute("name") == "ÖܽÜÂ×")//Èç¹ûnameÊôÐÔÖ
Ïà¹ØÎĵµ£º
ÔÚʹÓÃasp.net±àдwebserviceʱ£¬Ä¬ÈÏÇé¿öÏÂÊDz»Ö§³ÖsessionµÄ£¬µ«ÎÒÃÇ¿ÉÒÔ°ÑWebMethodµÄEnableSessionÑ¡ÏîÉèΪtrueÀ´ÏÔʽµÄ´ò¿ªËü£¬Çë¿´ÒÔÏÂÀý×Ó£º
1 н¨ÍøÕ¾WebSite
2 н¨web·þÎñWebService.asmx£¬Ëü¾ßÓÐÒÔÏÂÁ½¸ö·½·¨£º
[WebMethod(EnableSession = true)]
public string Login(string name)
{
  ......
Global.asaxÎļþ£¬ÓÐʱºò½Ð×öÓ¦ÓóÌÐòÎļþ£¬ÌṩÁËÒ»ÖÖÔÚÒ»¸öÖÐÐÄλÖÃÏìÓ¦Ó¦ÓóÌÐò¼¶»òÄ£¿é¼¶Ê¼þµÄ·½·¨¡£Äã¿ÉÒÔʹÓÃÕâ¸öÎļþʵÏÖÓ¦ÓóÌÐò°²È«ÐÔÒÔ¼°ÆäËüһЩÈÎÎñ¡£ÏÂÃæÈÃÎÒÃÇÏêϸ¿´Ò»ÏÂÈçºÎÔÚÓ¦Óù¤×÷ÖÐʹÓÃÕâ¸öÎļþ¡£
¸ÅÊö
Global.asaxλÓÚÓ¦ÓóÌÐò¸ùĿ¼Ï¡£ËäÈ»VisualStudio.NET»á×Ô¶¯²åÈëÕâ¸öÎ ......
class ImportExportToExcel
{
public class ImportExportToExcel
{
private string strConn;
private System.Windows.Forms.OpenFileDialog openFileDlg = new System.Windows.Forms.OpenFileDialog();
private System.Windows.Forms.SaveFileDialog saveFi ......
/*
Êý¾Ý¿â²éѯXML½á¹¹£¬FOR XML PATH Óï¾äµÄÓ¦ÓÃ
*/
FOR XML PATH Óï¾äµÄÓ¦ÓÃ:
CREATE TABLE TempTable(UserID int , UserName nvarchar(50));
insert into TempTable (UserID,UserName) values (1,'a')
insert into TempTable (UserID,UserName) values (2,'b')
select UserID,UserName from TempTable FOR ......