XmlDocument xmlDocument=new XmlDocument();
XmlElement root = xmlDocument.CreateElement("", "root", "");
xmlDocument.AppendChild(root);
XmlNode rootnode = xmlDocument.SelectSingleNode("root");
for (int i = ; i < table.Rows.Count; i++)
{
XmlElement item = xmlDocument.CreateElement("item");
item.SetAttribute("number", table.Rows[i]["number"].ToString());
item.SetAttribute("name", table.Rows[i]["name"].ToString());
item.SetAttribute("specification", table.Rows[i]["specification"].ToString());
item.SetAttribute("comments", table.Rows[i]["comments"].ToString());
root.AppendChild(item);
}
string xmlstr = xmlDocument.InnerXml;

以上是C# xml的写入方法,从数据库表读取的数据,写入xml中,保存为字符串格式。

xml写入的更多相关文章

  1. dom4j工具对XML写入修改删除操作实现

    import org.dom4j.Document; import org.dom4j.DocumentException; import org.dom4j.io.SAXReader; import ...

  2. config.xml写入和读取

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...

  3. log4j.xml写入数据库,只有SQL和参数,无其他信息

    <?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE log4j:configuration SY ...

  4. Boost解析xml——xml写入

    <?xml version="1.0" encoding="utf-8"?> <Config> <Item name=" ...

  5. 监控节点 xml写入数据库 存储过程

    USE [Appserver] GO /****** Object:  StoredProcedure [AppServer].[ImportNodeRelationData]    Script D ...

  6. C#程序中:如何向xml文件中写入数据和读取数据

    xml文件作为外部信息存储文件使用简单,方便,其结构和表格略有相似,下面简单的说一下xml文件内容的读取 …… using System.Xml;using System.IO;namespace W ...

  7. C#操作XMl文件(2):使用XmlReader和XmlWriter实现读取和写入

    这次使用操作Xml较为常用的方法:使用XMlreader和Xmlwriter 1:读取xml文件的数学和元素 XmlReaderSettings settings = new XmlReaderSet ...

  8. ASP.NET写入和读取xml文件

    xml是一种可扩展标记语言,在电子计算机中,标记指计算机所能理解的信息符号,通过此种标记,计算机之间可以处理包含各种的信息比如文章等.它可以用来标记数据.定义数据类型,是一种允许用户对自己的标记语言进 ...

  9. winform,xml读取与写入

    创建两个xml文件,一个 xml做为模板配置项,另一个做为临时接收数据. private static string localPath = System.Environment.CurrentDir ...

随机推荐

  1. 关于oracle数据库启动报ORA-01122,ORA-01110,ORA-01203错误的解决方法

    ORACLE 数据库空间裸设备出问题了,启动oracle失败,解决方法问题现象:     启动ORACLE的时候报如下的错误:        Database mounted.      ORA-01 ...

  2. C++ - 容器概述

    一 迭代器iterator 5种类别 常用的迭代器 常用的迭代器 二 分配算符Allocators 三 容器简介 STL标准容器类简介 标准容器类 说明 顺序性容器 关联容器 容器适配器 所有标准库共 ...

  3. leetcode38

    public class Solution { public string CountAndSay(int n) { //1 //11 //21 //1211 //111221 //312211 // ...

  4. 点赞功能实现 $(tag).css('属性', '样式')

    1. 创建标签 document.createElement() 2.$(tag).css('属性', 样式) 赋予标签属性样式 3.设置定时器 改变位置 大小 <!DOCTYPE html&g ...

  5. Tomcat 性能监控工具jvisualvm, JConsole

    配置: 重启Tomcat

  6. JPA with Hibernate implementation

    https://code.google.com/p/jpa-basics-tutorial/source/checkout http://alextretyakov.blogspot.com/2013 ...

  7. linux下实时查看log

    1.先切换到:cd usr/local/tomcat5/logs2.tail -f catalina.out3.这样运行时就可以实时查看运行日志了 Ctrl+c 是退出tail命令. 顺便讲一下lin ...

  8. 在VMware Workstation中安装Ubuntu Server 16.04.5图解教程

    最近要在Ubuntu中部署openstack,为了节省空间和内存,最终选择了Ubuntu服务器.看了很多前辈和大佬的安装教程,在这里记录一下我自己的Ubuntu Server 16.04.5的安装过程 ...

  9. A*—java代码

    import java.util.ArrayList; // A*算法寻路 public class AStar2 { public static final int[][] maps = { {0, ...

  10. ADT离线安装

    1.安装eclipse软件.安装后点击HELP菜单,找到下面的Install New Software并点击. 2.之后会弹出一个对话框,然后我们点击add,接下来弹出ADD对话框,然后我们再点击ar ...