XmlDocument To String
一.从String xml到XmlDocument的:
string xml = "<XML><Test>Hello World</Test></XML>"
XmlDocument doc = new XmlDocument();
xml.loadXml(xml);
二.将XmlDocument内容 转换成String xml
//(1)如果只要求字符串的话用xmlDocument 的 OuterXml 方法就可以实现:
doc.OutXml; //(2)转字节流的方式
//这种方式可以把 xmlDocument 内容变成比较符合标准格式的 xml 字符串,例如:
//<?xml version="1.0" encoding="utf-8"?>
//<XML>
// <Test>Hello World</Test>
//</XML>
// xmlDocument to string
public static string xmlDocument2String(XmlDataDocument doc)
{
MemoryStream stream = new MemoryStream();
XmlTextWriter writer = new XmlTextWriter(stream, System.Text.Encoding.UTF8);
writer.Formatting = Formatting.Indented;
doc.Save(writer); StreamReader sr = new StreamReader(stream, System.Text.Encoding.UTF8);
stream.Position = 0;
string xmlstring = sr.ReadToEnd();
sr.Close();
stream.Close(); return xmlstring;
} //(3)先写到本地文件,再字符串形式流读取:
public string XmltoString(string path)
{
string strXML = "";
string strLine = "";
StreamReader objReader = new StreamReader(path);
// read line
while ((strLine = objReader.ReadLine()) != null)
{
strXML += strLine;
}
objReader.Close(); return strXML;
}
XmlDocument To String的更多相关文章
- XMLDocument转为String 摘录
public static string FormatXmlString(string xmlString) { XmlDocument document = new XmlDocument(); d ...
- XmlDocument和XDocument转String
1:XDocument转String直接使用ToString();XNode里面重写了ToString()方法 2:XmlDocument转String需要写代码 using System; usin ...
- XML 之 与Json或String的相互转换
1.XML与String的相互转换 [1] XML 转为 String //载入Xml文件 XmlDocument xdoc = new XmlDocument(); xdoc.Load(" ...
- XmlDocument操作
一.基本操作:XmlDocument 写 class Program { static void Main(string[] args) { // 使用DOM操作,常用的类:XmlDocument.X ...
- C#遍历XmlDocument对象所有节点名称、类型、属性(Attribute)
C#遍历XmlDocument对象所有节点名称.类型.属性(Attribute) 源码下载 代码 static void Main(string[] args) { System.Xml.XmlDoc ...
- XmlDocument.LoadXml和Load的区别
LoadXml:从指定的字符串加载 XML 文档. eg:doc.LoadXml("<root>aa</root>"); .csharpcode, .csh ...
- XmlDocument.selectNodes() and selectSingleNode()的xpath的学习资料
Xpath网页: http://www.w3school.com.cn/xpath/xpath_syntax.asp XDocument.parse(string)类似于XmlDocument.loa ...
- .net工具类
ConvertHelper public class ConvertHelper { /// <summary> /// 转换类型 /// </summary> /// < ...
- C#操作XML的通用方法总结
转载至http://www.cnblogs.com/pengze0902/p/5947997.html 1.创建xml 复制代码 /// <summary> /// 创建XML文档 /// ...
随机推荐
- ubuntu安装遇到的问题
检查磁盘发现严重错误 解决办法 进入ubuntu启动菜单,选中*ubuntu后按e进入启动项编辑模式,找到ro rootflags=sync把ro改成rw,再按F10启动 启动后打开终端termina ...
- Thinking In Java 读书笔记
面向对象语言,五个基本特性: 1)万物皆为对象. 2)程序是对象的集合,他们通过发送消息来告知彼此所要做的. 3)每个对象都有自己的由其他对象所构成的存储. 4)每个对象都拥有其类型.即:每个对象都是 ...
- 使用BusyBox制作根文件系统【转】
本文转载自:http://www.cnblogs.com/lidabo/p/5300180.html 1.BusyBox简介 BusyBox 是很多标准 Linux 工具的一个单个可执行实现.Busy ...
- 160922、配置:spring通过profile或@profile配置不同的环境(测试、开发、生产)
一.配置环境 applicationContext.xml中添加下边的内容(develop:开发环境,production:生产环境,test:测试环境) 注意:profile的定义一定要在文档的最下 ...
- spring命名空间不需要版本号
为什么dubbo启动没有问题? 这篇blog源于一个疑问: 我们公司使了阿里的dubbo,但是阿里的开源网站http://code.alibabatech.com,挂掉有好几个月了,为什么我们的应用启 ...
- yii2通过foreach循环遍历在一个用户组中取出id去另一表里查寻信息并且带着信息合并原数组信息---案例
yii2通过foreach循环遍历在一个用户组中取出id去另一表里查寻信息并且带着信息合并元数组信息---案例 public function actionRandomLists(){ //查询到了所 ...
- nginx完美支持tp框架
nginx完美支持tp框架 server { listen 80; server_name mit.520m.com.cn; access_log /data/wwwlogs/mit.520m.com ...
- drawer principle in Combinatorics
Problem 1: Given an array of real number with length (n2 + 1) A: a1, a2, ... , an2+1. Prove that th ...
- U3D UGUI学习4 - Text
1.对应NGUI的四种文字显示模式 Shrink Content 对应NGUI第一种模式 勾选Best Fit 但似乎有一个Bug,文字过多的时候会爆框.解决方法是改变Line Spacing ...
- oneThink安装出错解决
在Wampserver3.0.0(apache2.4.17+php5.6.15+mysql5.7.9)版本中oneThink安装用1.1github版,不要用1.1开发版,不然安装的时候数据库导入时b ...