一.从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的更多相关文章

  1. XMLDocument转为String 摘录

    public static string FormatXmlString(string xmlString) { XmlDocument document = new XmlDocument(); d ...

  2. XmlDocument和XDocument转String

    1:XDocument转String直接使用ToString();XNode里面重写了ToString()方法 2:XmlDocument转String需要写代码 using System; usin ...

  3. XML 之 与Json或String的相互转换

    1.XML与String的相互转换 [1] XML 转为 String //载入Xml文件 XmlDocument xdoc = new XmlDocument(); xdoc.Load(" ...

  4. XmlDocument操作

    一.基本操作:XmlDocument 写 class Program { static void Main(string[] args) { // 使用DOM操作,常用的类:XmlDocument.X ...

  5. C#遍历XmlDocument对象所有节点名称、类型、属性(Attribute)

    C#遍历XmlDocument对象所有节点名称.类型.属性(Attribute) 源码下载 代码 static void Main(string[] args) { System.Xml.XmlDoc ...

  6. XmlDocument.LoadXml和Load的区别

    LoadXml:从指定的字符串加载 XML 文档. eg:doc.LoadXml("<root>aa</root>"); .csharpcode, .csh ...

  7. XmlDocument.selectNodes() and selectSingleNode()的xpath的学习资料

    Xpath网页: http://www.w3school.com.cn/xpath/xpath_syntax.asp XDocument.parse(string)类似于XmlDocument.loa ...

  8. .net工具类

    ConvertHelper public class ConvertHelper { /// <summary> /// 转换类型 /// </summary> /// < ...

  9. C#操作XML的通用方法总结

    转载至http://www.cnblogs.com/pengze0902/p/5947997.html 1.创建xml 复制代码 /// <summary> /// 创建XML文档 /// ...

随机推荐

  1. history and its relevant variables in Linux/GNU and Mac OS history命令以及相关环境变量

    对于Terminalor们,history命令并不陌生,什么!n, !!更是很常用的,而且您在命令行敲的cmds是默认保存在/home/$USER/.bash_history(linux) /User ...

  2. Linux 下多核CPU知识【转】

    转自:http://www.cnblogs.com/dongzhiquan/archive/2012/02/16/2354977.html 1. 在Linux下,如何确认是多核或多CPU: #cat ...

  3. eclipse怎么设置字体大小

    eclipse怎么设置字体大小

  4. anroid 查看签名信息的方法

    1.把app改成压缩文件 2.解压以后找到META-INF\CERT.RSA 3.在CMD命令行里面输入:  keytool -printcert -file  E:\META-INF\CERT.RS ...

  5. node-webkit教程<>Native UI API 之Menu(菜单)

    node-webkit教程(6)Native UI API 之Menu(菜单)1 前言... 2 6.1  Menu 概述... 3 6.2  menu api6 6.2.1  new Menu([o ...

  6. Effective C++第三遍

    试图调用private的copy或赋值函数是编译期错误,而调用没有具体定义的函数则是连接期错误. 以对象管理资源:智能指针RAII(资源获取立即初始化)后都是对象,但有时候,比如(API的)函数参数要 ...

  7. SQLITE3 使用总结

    转自: http://blog.chinaunix.net/uid-8447633-id-3321394.html 前序: Sqlite3 的确很好用.小巧.速度快.但是因为非微软的产品,帮助文档总觉 ...

  8. ArrayList集合的实现原理

    一. ArrayList概述: ArrayList是基于数组实现的,是一个动态数组,其容量能自动增长,类似于C语言中的动态申请内存,动态增长内存. ArrayList不是线程安全的,只能用在单线程环境 ...

  9. HDU 1014:Uniform Generator

    Uniform Generator Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  10. hiho一下,第115周,FF,EK,DINIC

    题目1 : 网络流一·Ford-Fulkerson算法 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho住在P市,P市是一个很大很大的城市,所以也面临着一个 ...