XML转换成HTML

1.//装载xsl

XslCompiledTransform xslt = new XslCompiledTransform();

xslt.Load("output.xsl");

2.//执行转换和输出的结果文件

xslt.Transform("Company.xml","Report.html");

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
///ETDZXML 的摘要说明
/// </summary>
public class ETDZXML
{
/// <summary>
/// 将XML对象转换成文本
/// </summary>
/// <param name="xmd">XML对象</param>
/// <returns>返回XML文件的文本字符串</returns>
public static string ToString(System.Xml.XmlDocument xmd)
{
string str = null;
System.IO.StringWriter sw = new System.IO.StringWriter();
System.Xml.XmlTextWriter tx = new System.Xml.XmlTextWriter(sw);
xmd.WriteTo(tx);
str = sw.ToString();
sw.Close();
sw = null;
tx.Close();
tx = null;
return str;
}

/// <summary>
/// 将文本保存成XML文件
/// </summary>
/// <param name="_xml">XML文本</param>
/// <param name="_xmlFullFilename">XML文件名</param>
public static void SaveXML(string _xml, string _xmlFullFilename)
{
System.IO.FileStream FS = new System.IO.FileStream(_xmlFullFilename, System.IO.FileMode.Create);
System.IO.StreamWriter sw = new System.IO.StreamWriter(FS, System.Text.Encoding.Default);
//System.Xml.XmlTextWriter myXml = new System.Xml.XmlTextWriter(FS, System.Text.Encoding.Default);
sw.Write(_xml);
sw.Close();
sw = null;
FS.Close();
FS = null;
GC.Collect();
}

/// <summary>
/// 读取文本文件
/// </summary>
/// <param name="_xmlRelPath">文件的相对路径</param>
/// <returns>文本字符串</returns>
public static string ReadXML(string _xmlRelPath)
{
System.IO.StreamReader sr = new System.IO.StreamReader(HttpContext.Current.Server.MapPath(_xmlRelPath).Replace("\\xmls\\", "\\"));
string xml = sr.ReadToEnd();
sr.Close();
sr = null;
return xml;
}

/// <summary>
/// 读取文本文件
/// </summary>
/// <param name="_filePath">文件的绝对路径</param>
/// <returns>文本字符串</returns>
public static string ReadText(string _filePath)
{
System.IO.StreamReader sr = new System.IO.StreamReader(_filePath);
string txt = sr.ReadToEnd();
sr.Close();
sr = null;
return txt;
}

/// <summary>
/// 向XML文档对象插入节点及其属性
/// </summary>
/// <param name="xmd">XML文档对象(ref)</param>
/// <param name="_nodeName">节点名称</param>
/// <param name="_attrNames">属性名数组</param>
/// <param name="_attrVals">属性值数组</param>
public static void AddNode(ref System.Xml.XmlDocument xmd, string _containerNodeName, string _nodeName, string[] _attrNames, string[] _attrVals)
{

System.Xml.XmlElement xmeN = xmd.CreateElement("", _nodeName, "");
xmd.SelectSingleNode(_containerNodeName).AppendChild(xmeN);

for (int i = 0; i < _attrNames.Length; i++)
{
System.Xml.XmlAttribute xa = xmd.CreateAttribute(_attrNames[i]);
xa.InnerText = _attrVals[i];
xmeN.Attributes.Append(xa);
}
}

/// <summary>
/// 向XML文档对象节点(多个)插入多个子节点及其属性
/// </summary>
/// <param name="xmd">XML文档对象(ref)</param>
/// <param name="_nodeName">节点名称</param>
/// <param name="_attrNames">属性名数组</param>
/// <param name="_attrVals">属性值数组</param>
public static void AddNodes(ref System.Xml.XmlDocument xmd, string _containerNodePath, string _nodeName, string[] _attrNames, string[] _attrVals)
{

System.Xml.XmlElement xmeN = xmd.CreateElement("", _nodeName, "");
System.Xml.XmlNodeList xnl = xmd.SelectNodes(_containerNodePath);
xnl[xnl.Count - 1].AppendChild(xmeN);

for (int i = 0; i < _attrNames.Length; i++)
{
System.Xml.XmlAttribute xa = xmd.CreateAttribute(_attrNames[i]);
xa.InnerText = _attrVals[i];
xmeN.Attributes.Append(xa);
}
}
}

C#操作XML类的更多相关文章

  1. .NET操作Xml类

    using System; using System.Collections.Generic; using System.Text; using System.Data; using System.I ...

  2. PHP DOMDocument操作 XML类 属性、方法

    属性: Attributes 存储节点的属性列表(只读) childNodes 存储节点的子节点列表(只读) dataType 返回此节点的数据类型 Definition 以DTD或XML模式给出的节 ...

  3. java分享第十七天-01(封装操作xml类)

    做自动化测试的人,都应该对XPATH很熟悉了,但是在用JAVA解析XML时,我们通常是一层层的遍历进去,这样的代码的局限性很大,也不方便,于是我们结合一下XPATH,来解决这个问题.所需要的JAR包: ...

  4. XML格式示例 与 XML操作(读取)类封装

    header('Content-Type: text/xml'); <?xml version="1.0" encoding="utf-8" standa ...

  5. C#XmlHelper操作Xml文档的帮助类

    using System.Xml; using System.Data; namespace DotNet.Utilities { /// <summary> /// Xml的操作公共类 ...

  6. [XML] C# XmlHelper操作Xml文档的帮助类 (转载)

    点击下载 XmlHelper.rar 主要功能如下所示 /// <summary> /// 类说明:XmlHelper /// 编 码 人:苏飞 /// 联系方式:361983679 // ...

  7. C#操作Xml树的扩展类

    本文提供一个操作Xml树的扩展类,与将xml字符串直接映射成实体对象的使用方法,供大家参考,学习. 下面附上源码 using System; using System.Collections.Gene ...

  8. C#操作xml完整类文件

    C#操作xml完整类文件 xml_oper.cs using ...System; using System.Data; using System.Web; using System.Xml; /** ...

  9. 使用dom4j类操作xml文档

    dom4j操作xml数据 1.Document对象相关 ①读取XML文件,获得document对象. SAXReader reader = new SAXReader(); Document docu ...

随机推荐

  1. IOS开发之——保存图片到相册的功能实现

    //保存      UIButton *saveBtn = [[UIButton alloc] init];    //    saveBtn.frame = CGRectMake((screenWi ...

  2. 学习笔记——Maven 内置变量

    Maven内置变量说明: ${basedir} 项目根目录(即pom.xml文件所在目录) ${project.build.directory} 构建目录,缺省为target目录 ${project. ...

  3. WPF MVVM实现TreeView

    今天有点时间,做个小例子WPF MVVM 实现TreeView 只是一个思路大家可以自由扩展 文章最后给出了源码下载地址 图1   图2     模版加上了一个checkbox,选中父类的checkb ...

  4. 第十课:CSS选择器的介绍和区分

    IE7以及以下版本: getElementById是不区分表单元素ID与Name的,因此如果有一个表单元素只定义name,并与我们的目标元素ID同名,并且我们的目标元素在它的后面,那么就会选择到那个表 ...

  5. Set up gradle HiveMind

    HiveMind is a comprehensive ERP application for service organizations. It includes a project managem ...

  6. php发送get、post请求的6种方法简明总结

    方法1: 用file_get_contents 以get方式获取内容: ? 1 2 3 4 5 <?php $url='http://www.jb51.net/'; $html = file_g ...

  7. “耐撕”团队记账本 剧透

    β发布之后,我们团队开始fork"OneZero"团队的记账本程序.我们在原来的基础上添加了以下功能: 下面是我们团队记账本程序演示的视频:http://v.youku.com/v ...

  8. “耐撕”团队 2016.04.05 站立会议

    1. 时间: 20:10--20:25  共计15分钟. 2. 成员: Z 郑蕊 * 组长 (博客:http://www.cnblogs.com/zhengrui0452/), P 濮成林(博客:ht ...

  9. 【转载】Velocity模板引擎的介绍和基本的模板语言语法使用

    原文地址http://www.itzhai.com/the-introduction-of-the-velocity-template-engine-template-language-syntax- ...

  10. poj2528 线段树+离散化

    由于坐标可能很大,此时需要离散化,将值转化为对应的坐标. #include<stdio.h> #include<algorithm> using namespace std; ...