一.从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. 读 《JavaScript: The Good Parts》 有感

    提炼出一门语言或技术的 Good Parts, 使用该子集去构造健壮稳固的应用. 我们总是倾向于去学习和使用所有的语言特性,好像凡是新的,凡是提供了的, 就有必要去使用: 这本书告诉我们, 要有选择性 ...

  2. Linux内核配置机制(make menuconfig 、Kconfig、Makefile)讲解【转】

    本文转载自:http://www.codexiu.cn/linux/blog/34801/ 前面我们介绍模块编程的时候介绍了驱动进入内核有两种方式:模块和直接编译进内核,并介绍了模块的一种编译方式—— ...

  3. JSP在项目中的路径问题

    一.JSP中获得当前应用的相对路径和绝对路径  根目录所对应的绝对路径 : request.getRequestURI() 文件的绝对路径 : application.getRealPath(requ ...

  4. android 下的技巧

    1.删除屏幕的手势锁定 adb shell #登录 su $切换到su用户(手机需要root) cd /data/system #切换目录 rv gesture.key # 删除锁屏文件,然后进去的时 ...

  5. 【jqGrid for ASP.NET MVC Documentation】.学习笔记.4.性能

    1 HTML / ViewState 大小 1.1 HTML 大小 jqGrid for ASP.NET MVC 使用最佳的客户端渲染,意味着 HTML gird 的 尺寸是最小的.事实上,只有 gr ...

  6. mysql delete数据 空间占用不减少的解决办法

    今天空间商告诉我数据库空间满了,检查了一下,发现网站用户行为记录数据表竟然占了20多MB.积累了半年了,该删除释放一下空间了.果断delete之后发现数据库空间竟然没少,虽然数据记录数是零. 原来这是 ...

  7. Mootools插件-闪烁的标题

    转自:http://www.cnblogs.com/see7di/archive/2012/10/09/2716024.html 回想起来,我已经好久没有写点啥了,尤其是关于Mootools方面的东西 ...

  8. c#之xml

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.X ...

  9. c#游戏 剪刀石头

    电脑using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace sh ...

  10. Sqlite查询时间段内的数据问题解决!

    最近搞Sqlite本地查询,需求为查询某时间段内的数据,在SQL中我们都知道为: select * from tblName where rDate Between '2008-6-10' and   ...