一.从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. django models使用学习记录

    如何更新单个数据 example = User.objects.get(id=1) example.is_acitve=1 example.save() 如何更新多个数据 examples = Use ...

  2. 如何优化tomcat配置(从内存、并发、缓存4个方面)优化

    Tomcat有很多方面,我从内存.并发.缓存四个方面介绍优化方法.  ** 一.Tomcat内存优化 ** Tomcat内存优化主要是对 tomcat 启动参数优化,我们可以在 tomcat 的启动脚 ...

  3. JavaEE基础(十二)

    1.常见对象(Scanner的概述和方法介绍) A:Scanner的概述 B:Scanner的构造方法原理 Scanner(InputStream source) System类下有一个静态的字段: ...

  4. 深入浅出Windows Phone 8应用开发

    刚刚拿到<深入浅出Windows Phone 8应用开发>这本书,开始捣鼓我的Nokia Lumia 925T,已经有开发一个属于自己的App的想法了,计划先不公布了,等我这个App上线了 ...

  5. Win7家庭版包“已停止工作”

    在VS2010上依据接口,写了个WiFi共享软件,在Win7旗舰班上正确无误,而在却在Win7家庭版上运行不了,报“已停止工作”错误. 解决方法: 1.下载安装vs2010对应的.Net平台:Micr ...

  6. Python基础第一篇

    一.第一句python代码 1.python执行过程:1.加载内存-词法分析-语法分析-编译-执行 2.创建hello.py文件,输入内容 #!/usr/bin/env python print &q ...

  7. java面试每日一题12

    题目:打印出如下图案(菱形)     *    ***  ****** ********  ******   ***    * public class Diamond { public static ...

  8. [xcode]instruments来检验你的app

      原文网址:http://www.cocoachina.com/industry/20140114/7696.html     比较了好多关于instruments 还是发现老外写的比较牛逼.于是果 ...

  9. 【转】MYSQL入门学习之十三:自定义函数的基本操作

    转载地址:http://www.2cto.com/database/201212/177382.html 一.自定义函数(UDF)的特性和功能  www.2cto.com           函数能分 ...

  10. HDU(4528),BFS,2013腾讯编程马拉松初赛第五场(3月25日)

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=4528 小明系列故事——捉迷藏 Time Limit: 500/200 MS (Java/O ...