C#读取csv文件使用字符串拼接成XML

phone.csv

zhangsan1,123456789
zhangsan2,123456789
zhangsan3,123456789
static void Main(string[] args)
        {
            //XML
            //XML就是一个文件,用来存储数据,比如csv文件

            List<string> list = new List<string>();
            list.Add("<?xml version=\"1.0\" encoding=\"gb2312\" ?>");
            string[] lines = File.ReadAllLines("phone.csv", Encoding.Default);
            for (int i = 0; i < lines.Length; i++)
            {
                list.Add("\t<person id=\""+i.ToString("00000")+"\">");
                string[] temp = lines[i].Split(‘,‘);
                //加数据
                list.Add("\t\t<name>"+temp[0]+"</name>");
                list.Add("\t\t<phone>" + temp[1] + "</phone>");
                list.Add("\t</person>");
            }
            list.Add("</root>");

            File.WriteAllLines("xml.xml",list.ToArray(),Encoding.Default);
        }
时间: 2024-08-29 13:10:52

C#读取csv文件使用字符串拼接成XML的相关文章

读取csv文件,写入oracle数据库

/* * @(#)DataParse.java 2014年4月28日 */ package com.yihaodian.sa.doData; import java.io.BufferedReader;import java.io.File;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.IOException;import java.sql.Connection;import java.

Cocos2d-x Lua 读取Csv文件,更方便的使用数据

我的书上或者是我曾经出售的源码里,都有Csv文件的影子. 也许是先入为主吧,我工作那会用的最久的配置文件就是Csv,所以我在很多游戏里都会情不自禁地优先选择它. Csv文件,格式很简单,就是一行一条数据,字段之间用逗号分隔,策划也可以方便地使用Excel进行编辑. Csv格式的文件,解析起来也很简单,所以自己动手写写很快~(小若:我就喜欢拿来主义,你怎么着) 最近在用Lua写游戏,对于技能.怪物等配置,我还是选择用Csv~ 不得不说,Lua等脚本语言,在某些方面是C++没法比的,这次我就用Csv

Spring Batch示例: 读取CSV文件并写入MySQL数据库

Spring Batch示例: 读取CSV文件并写入MySQL数据库 GitHub版本: https://github.com/kimmking/SpringBatchReferenceCN/blob/master/01_introduction/Spring_Batch_MySQL.md 原文链接: Reading and writing CVS files with Spring Batch and MySQL 原文作者: Steven Haines - 技术架构师 下载本教程的源代码: S

Spring Batch使用示例: 读取CSV文件并写入MySQL数据库

GitHub版本: https://github.com/kimmking/SpringBatchReferenceCN/blob/master/01_introduction/Spring_Batch_MySQL.md ------------ 编写批处理程序来处理GB级别数据量无疑是种海啸般难以面对的任务,但我们可以用Spring Batch将其拆解为小块小块的(chunk). Spring Batch 是Spring框架的一个模块,专门设计来对各种类型的文件进行批量处理. 本文先讲解一个简

Python 中读取csv文件中有中文的情况

Python 中读取csv文件中有中文的情况,提示编码问题: 读取的时候: import sys reload(sys) #中文错误 sys.setdefaultencoding( "utf-8" ) save 存储的时候: dataframe可以使用to_csv方法方便地导出到csv文件中,如果数据中含有中文,一般encoding指定为"utf-8″,否则导出时程序会因为不能识别相应的字符串而抛出异常,index指定为False表示不用导出dataframe的index数据

python-pandas读取mongodb、读取csv文件

续上一篇博客(‘’selenium爬取NBA并将数据存储到MongoDB‘)https://www.cnblogs.com/lutt/p/10810581.html 本篇的内容是将存储到mongo的数据用pandas读取出来,存到CSV文件,然后pandas读取CSV文件. 其中mongo的操作涉及到授权的问题: 如果遇到报错关于authenticate的,需要加授权,用时需要将各参数换成自己的 #导入相应的包 import pymongo import pandas as pd from pa

C++ 把数组数据存入 CSV 文件,以及读取 CSV 文件的数据

1. CSV-百度百科 2. 代码 #pragma once //Microsoft Visual Studio 2015 Enterprise #include<iostream> #include<fstream> #include<string> #include<vector> #include<cstdio> #include<cstdlib> using namespace std; template<typenam

sparkR读取csv文件

sparkR读取csv文件 The general method for creating SparkDataFrames from data sources is read.df. This method takes in the path for the file to load and the type of data source, and the currently active SparkSession will be used automatically. SparkR suppo

php读取csv文件类

php处理csv文件类: http://www.php100.com/cover/php/540.html <?php define("CSV_Start", 0); define("CSV_Quoted", 1); define("CSV_Quoted2", 2); define("CSV_Unquoted", 3); function readCSV($fh, $len, $delimiter = ',', $enc