/// <summary>
/// xml文件转换为CSV
/// </summary>
/// <param name="fileName">xml格式文件</param>
/// <returns>true - CSV转换成功</returns>
private static bool ToCSV(string fileName)
{
var xmlFilePath = @"e:\ceshi.xml"; //System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + @"\" + fileName; var csv = System.Xml.Linq.XElement.Load(xmlFilePath).Elements("Check")
.Where(a => a.Attribute("Name").Value == "Windows Security Updates")
.Elements("Detail").Elements("UpdateData")
.Where(a => a.Attribute("IsInstalled").Value == "false")
.OrderByDescending(a => a.Attribute("Severity").Value)
.Select(b => string.Format("{0},{1},{2}",
"KB" + (string)b.Attribute("KBID"),
(int)b.Attribute("Severity"),
Environment.NewLine
))
.Aggregate(new StringBuilder(), (sb, s) => sb.Append(s), sb => sb.ToString()); string csvPath = xmlFilePath.Substring(, xmlFilePath.Length - ) + "csv";
System.Text.Encoding enc = System.Text.Encoding.GetEncoding("shift_jis"); using (System.IO.StreamWriter sw = new System.IO.StreamWriter(csvPath, false, enc))
{
// 如果要在标题的开头显示ID列,请将其括在双引号中
// See: http://pasofaq.jp/office/excel/sylk.htm
string header = "KBID,Severity";
sw.WriteLine(header); sw.WriteLine(csv);
} return true;
}

xml转换csv的更多相关文章

  1. Java 将Excel转为图片、html、XPS、XML、CSV

    通过文档格式转换,可满足不同办公场合对文档操作的需求.本文将介绍转换Excel文档为其他常见文档格式的方法.通过文中的方法,可支持将Excel转换为包括PDF.图片.html.XPS.XML.CSV. ...

  2. Dom4j把xml转换成Map(固定格式)

    /** * 可解析list * * @param fileName * @return * @throws Exception */ @SuppressWarnings("unchecked ...

  3. Dom4j把xml转换成Map(非固定格式)

    将xml转换成Map,能够应对不用结构的xml,而不是只针对固定格式的xml.转换规则:1.主要是Map与List的互相嵌套2.同名称的节点会被装进List 示例: import java.util. ...

  4. 如何在ASP.NET中用C#将XML转换成JSON

    本文旨在介绍如果通过C#将获取到的XML文档转换成对应的JSON格式字符串,然后将其输出到页面前端,以供JavaScript代码解析使用.或许你可以直接利用JavaScript代码通过Ajax的方式来 ...

  5. 如何在ASP.NET中用C#将XML转换成JSON 【转】

      本文旨在介绍如果通过C#将获取到的XML文档转换成对应的JSON格式字符串,然后将其输出到页面前端,以供JavaScript代码解析使用.或许你可以直接利用JavaScript代码通过Ajax的方 ...

  6. 字符串json转换为xml xml转换json

    原文:字符串json转换为xml xml转换json // To convert an XML node contained in string xml into a JSON string XmlD ...

  7. C#将XML转换成JSON转换XML

    原文:C#将XML转换成JSON转换XML using System; using System.Collections.Generic; using System.Linq; using Syste ...

  8. 转 JSON与XML转换

    这两天处理模块的联调工作,在json与XML转换中出现了一些奇怪的问题,仔细究来,实为对org.json.*包知之太少.晚上baidu.google一下,找出了问题出现的原因.在模块中,使用了两个方法 ...

  9. Android Strings.xml To CSV / Excel互转

    Android Strings.xml To CSV/Excel互转https://blog.csdn.net/hzxpyjq/article/details/50686983https://blog ...

随机推荐

  1. 2018 Spring Single Training B (uva 572,HihoCoder 1632,POJ 2387,POJ 2236,UVA 10054,HDU 2141)

    这场比赛可以说是灰常的水了,涨信心场?? 今下午义务劳动,去拿着锄头发了将近一小时呆,发现自己实在是干不了什么,就跑到实验室打比赛了~ 之前的比赛补题补了这么久连一场完整的都没补完,结果这场比完后一小 ...

  2. 【bzoj1602】[Usaco2008 Oct]牧场行走

    1602: [Usaco2008 Oct]牧场行走 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1793  Solved: 935[Submit][St ...

  3. 551. Student Attendance Record I 从字符串判断学生考勤

    [抄题]: You are given a string representing an attendance record for a student. The record only contai ...

  4. servlet模板

    package ${enclosing_package};import java.io.IOException;import javax.servlet.ServletException;import ...

  5. atom markdown报错:AssertionError: html-pdf: Failed to load PhantomJS module.

    今天安装markdown-pdf之后运行的时候报错: AssertionError: html-pdf: Failed to load PhantomJS module. You have to se ...

  6. Asp.net MVC 基于Area的路由映射

    对于一个较大规模的Web应用,我们可以从功能上通过Area将其划分为较小的单元.每个Area相当于一个独立的子系统,具有一套包含Models.Views和Controller在内的目录结构和配置文件. ...

  7. 关于.net DateTime 的一些事儿

    最近开发的过程中遇到一种情况,在.net 程序中获取的Datetime格式的时间,在存入SQL server中,毫秒部分丢失. 这个是个很奇怪的状况,因为在Debug的时候,Datetime的变量的确 ...

  8. SignalR 跨域解决方案全面

    SignalR 分:PersistentConnection和Hub 2种模式. 跨域又分:UseCors和JsonP  2种方法 所以例子写了4种. 核心代码: UseCors //Persiste ...

  9. 用firebug 进行表单自定义提交

    在一些限制网页功能的场合,例如,防止复制内容,防止重复提交,限制操作的时间段/用户等,网页上一些按钮是灰化的(禁用的),这通常是通过设置元素的 disable属性来实现的.但在后台并没有做相应的功能限 ...

  10. angular 服务之间依赖注入

    import { Injectable } from '@angular/core'; @Injectable() export class LoggerServiceService { constr ...