惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Docker
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - Franky
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
A
About on SuperTechFans
博客园 - 【当耐特】
Microsoft Security Blog
Microsoft Security Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The GitHub Blog
The GitHub Blog
雷峰网
雷峰网
博客园_首页
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
IT之家
IT之家
博客园 - 叶小钗
Google DeepMind News
Google DeepMind News
aimingoo的专栏
aimingoo的专栏
博客园 - 聂微东
B
Blog RSS Feed
H
Help Net Security
Recent Announcements
Recent Announcements
阮一峰的网络日志
阮一峰的网络日志
D
DataBreaches.Net
L
LangChain Blog
Vercel News
Vercel News

博客园 - Lee-hp

SQL:去掉重复行,只保留第一行 游标(转3) 游标(转2) 游标(转) Sql:取每个分类的前10条数据 sql:去掉重复行 水晶报表参考资料 页面信息抓取(二) 页面信息抓取 在GridView中绑定Radio 引用js脚本的奇怪问题 读博 好好工作,好好学习 游标使用——获取每个分类的前10条数据 Url传递中文 SQL触发器--插入时判断数据是否已存在 程序开发和参考资料 SQLServer - 标识列自增 锻炼你的专注力
xml操作
Lee-hp · 2007-04-11 · via 博客园 - Lee-hp

网上的一个xml操作类

在此基础上我加的一个 “插入一个节点和多个子节点”的方法
public void InsertNodes(string boot, string ChildNode, string [] Elements, string [] Contents)
{
    XmlNode objRootNode = objXmlDoc.SelectSingleNode(boot);
    XmlElement objChildNode = objXmlDoc.CreateElement(ChildNode);
    objRootNode.AppendChild(objChildNode);
    for(int i=0;i<Elements.Length;i++)
    {
        XmlElement objElement = objXmlDoc.CreateElement(Elements[i]);
        objElement.InnerText = Contents[i];
        objChildNode.AppendChild(objElement);
    }
}
/// <summary>
/// 写两级XML文件的通用方法
/// </summary>
/// <param name="filename">文件全路径</param>
/// <param name="comment">注释</param>
/// <param name="root">根元素 </param>
/// <param name="child1">一级子元素</param>
/// <param name="child2">二级子元素</param>
/// <param name="element">二级子元素值</param>
private void XmlWriteCommon(string filename, string comment, string root,string child1,string [] child2, string[,] element)
{
    XmlTextWriter xmlWrite = new XmlTextWriter(filename, Encoding.UTF8);
    xmlWrite.Formatting = Formatting.Indented;
    xmlWrite.WriteStartDocument(true);
    xmlWrite.WriteComment(comment);
    xmlWrite.WriteStartElement(root);
    for (int i = 0; i < element.GetLength(1); i++)
    {
        xmlWrite.WriteStartElement(child1);
        for(int j=0;j<child2.Length;j++)
        {
            xmlWrite.WriteElementString(child2[j], element[j, i]);
        }
        xmlWrite.WriteEndElement();
    }
    xmlWrite.WriteEndElement();
    xmlWrite.Flush();
    xmlWrite.Close();
}