一.从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. FreeOnTerminate 的线程在线程管理类的Destroy释放时手工释放的问题

    这个问题折腾了我整整一天. 有一个线程管理类,集中管理所有新建的线程, 线程统一在创建时标识 FreeOnTerminate 为 True. 因为有的线程是不限次循环的,所以在管理类最后 Destro ...

  2. iOS delegate, 代理/委托与协议.

    之前知知道iOS协议怎么写, 以为真的跟特么java接口一样, 后来发现完全不是. 首先, 说说应用场景, 就是当你要用一个程序类, 或者说逻辑类, 去控制一个storyboard里面的label, ...

  3. Linux Runtime PM介绍【转】

    转自:http://blog.csdn.net/wlwl0071986/article/details/42677403 一.Runtime PM引言 1. 背景 (1)display的需求 (2)系 ...

  4. TreeView htc 改写

    call the function loadTree(treeviewId) when body is loaded <body onload="loadTree('tvSelect' ...

  5. 【原创】Nexus搭建Maven私服

    前言: 公司一般都有个自己的私服来管理各种jar包,原因大概有这么3个,分别是: 1.有的公司不能访问外网,只能通过私服来管理jar包和插件: 2.公司网速比较慢,通过公司的私服来获取jar包比较快: ...

  6. Array JSON

    Tool: Online jsonviewer JSON: JavaScript Object Notation. JSON is a syntax for storing and exchangin ...

  7. Dynamics AX 2012 R2 切换环境后项目导入报错

        Reinhard重装了服务器.重装后,导入项目A报错,错误提示如下: A table, Extended Data Type, Base Enum or class called ???? a ...

  8. PHP编写的图片验证码类文件分享方法

    适用于自定义的验证码类! <?php/* * To change this license header, choose License Headers in Project Propertie ...

  9. 百度地图瓦片原理 | 百度map使用教程

    百度地图瓦片原理: http://blog.csdn.net/mygisforum/article/details/22997879 百度map使用教程: http://www.myexception ...

  10. ci中简单实用的权限管理

    实用的权限管理 对多数网站来说,使用完整的rbac权限管理杀鸡用牛刀绝对的吃力不讨好,因为我们只是简单分角色然后对角色进行管理行使其相对于的角色赋予的权限; 在实际的开发中用位运算来对权限进行验证是十 ...