M草儿

企业信息规划 ;业务流程再造 ;SaaS-CallCenter ;绿色节能建筑定量评估与认证……
相关源代码FORXML
  1using System;
  2using System.Xml;
  3using System.Collections;
  4using System.ComponentModel;
  5using System.Data;
  6using System.Data.OleDb;
  7using System.Data.Common;
  8using System.Drawing;
  9using System.Web;
 10using System.Web.SessionState;
 11using System.Web.UI;
 12using System.Web.UI.WebControls;
 13using System.Web.UI.HtmlControls;
 14
 15namespace Dtxml
 16{
 17    /// <summary>
 18    /// function is transform XML from a file to another file.
 19    /// copyright by Mcdule(wangzl)。
 20    /// </summary>

 21    public class WebForm2 : System.Web.UI.Page
 22    {
 23
 24        protected System.Web.UI.HtmlControls.HtmlGenericControl outResult2;
 25        protected System.Web.UI.HtmlControls.HtmlGenericControl outMessage;
 26
 27        private void Page_Load(object sender, System.EventArgs e)
 28        {
 29            
 30            string strConnect = System.Configuration.ConfigurationSettings.AppSettings["DsnWroxBooksOleDb"];
 31            string strCurrentPath = Request.PhysicalPath;
 32            string strXMLPath = strCurrentPath.Substring(0, strCurrentPath.LastIndexOf("\\")) + "\\booksource.xml";
 33            string strnewPath = strCurrentPath.Substring(0, strCurrentPath.LastIndexOf("\\")) + "\\rssxml.xml";
 34            string strSelect = "SELECT BookList.*, BookAuthors.FirstName, BookAuthors.LastName "
 35                + "FROM BookList INNER JOIN BookAuthors ON BookList.ISBN = BookAuthors.ISBN "
 36                + "WHERE BookList.ISBN LIKE '0764544%'";
 37
 38   
 39
 40            // 在此处放置用户代码以初始化页面
 41
 42            DataSet objDataSet = new DataSet();
 43
 44            try
 45            {
 46                // create a new OleDbConnection object using the connection string
 47                OleDbConnection objConnect = new OleDbConnection(strConnect);
 48
 49                // create a new OleDbDataAdapter using the connection object and select statement
 50                OleDbDataAdapter objDataAdapter = new OleDbDataAdapter(strSelect, objConnect);
 51
 52                // fill the dataset with data from the DataSetCommand object
 53                objDataAdapter.Fill(objDataSet, "item");
 54            }

 55            catch (Exception objError)
 56            {
 57                // display error details
 58                outMessage.InnerHtml = "<b>* Error while accessing data</b>.<br />"
 59                    + objError.Message + "<br />" + objError.Source;
 60                return;  //  and stop execution
 61            }

 62            objDataSet.WriteXml(strXMLPath);
 63            // create new empty XML Document object
 64            XmlDocument objnewDoc = new XmlDocument();
 65            XmlDocument objXMLDoc = new XmlDocument();
 66            objXMLDoc.Load(strXMLPath);
 67
 68            string strXpath="descendant::NewDataSet";
 69            XmlNode objNode;
 70            objNode=objXMLDoc.SelectSingleNode(strXpath);
 71            
 72
 73              objnewDoc.AppendChild(objXMLroot);
 74  //         ********************创建根节点RSS,并赋属性值************
 75              string  xmlstr="<rss version='2.0'>"+"</rss>";
 76
 77
 78            objnewDoc.LoadXml(xmlstr);
 79            XmlNode root=objnewDoc.DocumentElement;
 80    //**************创建所需的子节点,并赋值*****************
 81
 82            XmlElement elem=objnewDoc.CreateElement("Channel");
 83
 84            root.InsertAfter(elem,root.FirstChild);
 85
 86            XmlElement elemtitle=objnewDoc.CreateElement("title");
 87            elemtitle.InnerText="某某集团内网最新资讯";
 88
 89            XmlElement elemlink=objnewDoc.CreateElement("link");
 90            elemlink.InnerText=http://*.*.com;
 91
 92            XmlElement elemdes=objnewDoc.CreateElement("description");
 93            elemdes.InnerText="网站发布的最新文章、栏目和资源信息";
 94
 95            XmlElement elemlan=objnewDoc.CreateElement("language");
 96            elemlan.InnerText="zh-cn";
 97
 98
 99            string strSPath="descendant::Channel";
100
101            XmlNode SelNode=objnewDoc.SelectSingleNode(strSPath);
102            SelNode.AppendChild(elemtitle);
103            SelNode.AppendChild(elemlink);
104            SelNode.AppendChild(elemdes);
105            SelNode.AppendChild(elemlan);
106
107
108    //      ************从源文件中选择所需的节点导入目的文件中指定的位置***********
109            string strLPath = "descendant::item";
110            XmlNodeList colNodeList;
111            colNodeList = objXMLDoc.SelectNodes(strLPath);
112                
113            foreach (XmlNode objNd in colNodeList)
114            {
115
116                XmlNode objImDode=objnewDoc.ImportNode(objNd, true);
117                //            objnewDoc.DocumentElement.InsertAfter(objImDode,SelNode);
118                SelNode.AppendChild(objImDode);
119
120            }

121        
122                
123
124            objnewDoc.Save (strnewPath);
125
126        }

127
128        Web 窗体设计器生成的代码
147    }

148}

149

posted on 2005-10-03 23:05  草儿  阅读(197)  评论(0)    收藏  举报