zoukankan      html  css  js  c++  java
  • c#创建xml文档方法

     protected void MakeMXL(string newsid)
        {
            News news = NewsManager.GetNewsByNewsId(Convert.ToInt32(newsid));
            if (news.NewsId > 0)
            {
                //  创建XML文档,存在就删除再生成
                XmlDocument doc = new XmlDocument();
                XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "GB2312", null);
                doc.AppendChild(dec);
                //  创建根结点
                XmlElement XMLroot = doc.CreateElement("root");
                doc.AppendChild(XMLroot);
    
                //创建信息节点
                XmlElement newsroot = doc.CreateElement("News");
    
                XmlElement xmlnewsid = doc.CreateElement("News_ID");
                xmlnewsid.InnerText = news.NewsId.ToString();
                newsroot.AppendChild(xmlnewsid);
    
                XmlElement xmlnewstitle = doc.CreateElement("News_Title");
                xmlnewstitle.InnerText = news.NewsTitle.ToString();
                newsroot.AppendChild(xmlnewstitle);
    
                XmlElement xmlnewstime = doc.CreateElement("News_Time");
                xmlnewstime.InnerText = news.NewsTime.ToShortDateString();
                newsroot.AppendChild(xmlnewstime);
    
                XmlElement xmlnewsAuthor = doc.CreateElement("News_Author");
                xmlnewsAuthor.InnerText = news.NewsAuthor.ToString();
                newsroot.AppendChild(xmlnewsAuthor);
    
                XmlElement xmlnewsContent = doc.CreateElement("News_Content");
                xmlnewsContent.InnerText = news.NewsContent.ToString();
                newsroot.AppendChild(xmlnewsContent);
    
                XMLroot.AppendChild(newsroot);
    
                string xmlFile = comFunction.GetRootPath() + "\XML\" + newsid + ".XML";
                //  Response.Write(xmlFile);
                try
                {
                    doc.Save(xmlFile);
                    Console.Write(doc.OuterXml);
                    //  Message.Alert(LsUser.SelectedItem.Text + "用户,权限生成成功!", Page);
                }
                catch
                {
                    Message.Alert("生成失败!", Page);
                }
    
    
            }
  • 相关阅读:
    第三次作业
    第二次作业
    第一次作业
    仪仗队(欧拉函数)
    自己随便做的,没做完就没耐心继续了。呵呵
    从别处见到一位大神的代码 飞扬的小鸟(flappy bird)
    简易迷宫游戏c++
    STL做法 平衡树
    基于百度地图api + AngularJS 的入门地图
    javascript 简易文本编辑器
  • 原文地址:https://www.cnblogs.com/wdd812674802/p/10399334.html
Copyright © 2011-2022 走看看