1:XDocument转String直接使用ToString();XNode里面重写了ToString()方法

2:XmlDocument转String需要写代码

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
using System.IO; namespace XmlToString
{
class Program
{
static void Main(string[] args)
{
var xDoc = new XDocument(
new XElement("root111",
new XElement("dog",
new XText("哈哈哈"),
new XAttribute("color", "black")
),
//new XElement("cat"),
new XElement("pig", "pig is great")
));
Console.WriteLine(xDoc.ToString());
string strXml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><books><book>1</book><book>2</book><book>3</book><book>4</book></books>";
XmlDocument xx = new XmlDocument();
xx.LoadXml(strXml);
Console.WriteLine(xx.ToString());
StringWriter sw = new StringWriter();
XmlTextWriter xmlTextWriter = new XmlTextWriter(sw);
xx.WriteTo(xmlTextWriter);
Console.WriteLine(sw.ToString());
Console.ReadKey();
}
}
}

XmlDocument和XDocument转String的更多相关文章

  1. XmlDocument,XDocument相互转换

    XmlDocument,XDocument相互转换 using System; using System.Xml; using System.Xml.Linq; namespace MyTest { ...

  2. C# -- 使用XmlDocument或XDocument创建xml文件

    使用XmlDocument或XDocument创建xml文件 需引用:System.Xml; System.Xml.Linq; 1.使用XmlDocument创建xml(入门案例) static vo ...

  3. XmlValidationHelper XSD、Schema(XmlSchemaSet)、XmlReader(XmlValidationSettings)、XmlDocument、XDocument Validate

    namespace Test { using Microshaoft; using System; using System.Xml; using System.Xml.Linq; class Pro ...

  4. XmlDocument To String

    一.从String xml到XmlDocument的: string xml = "<XML><Test>Hello World</Test></X ...

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

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

  6. 七、Linq To XML:XElement、XDocument

    一.概述 LINQ to XMLLINQ to XML 是一种启用了 LINQ 的内存 XML 编程接口,使用它,可以在 .NET Framework.NET Framework 编程语言中处理 XM ...

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

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

  8. C# 使用XmlDocument类对XML文档进行操作

    原创地址:http://www.cnblogs.com/jfzhu/archive/2012/11/19/2778098.html 转载请注明出处 W3C制定了XML DOM标准.很多编程语言中多提供 ...

  9. C# 操作XML文档 使用XmlDocument类方法

    W3C制定了XML DOM标准.很多编程语言中多提供了支持W3C XML DOM标准的API.我在之前的文章中介绍过如何使用Javascript对XML文档进行加载与查询.在本文中,我来介绍一下.Ne ...

随机推荐

  1. Hibernate分页功能数据重复问题

    今天遇到一个很憋屈的问题那就是hibernate分页查询中出现重复数据,本来一直没有在意,以为是数据问题,但是一查程序和数据都没有问题,继续深入查看,找到问题了就是order By 时出的问题,唉.. ...

  2. STL 源码分析 (SGI版本, 侯捷著)

    前言 源码之前,了无秘密 algorithm的重要性 效率的重要性 采用Cygnus C++ 2.91 for windows cygwin-b20.1-full2.exe 下载地址:http://d ...

  3. Apache环境下搭建KodExplorer网盘

    Apache环境下搭建KodExplorer网盘 环境说明: 系统版本    CentOS 6.9 x86_64 软件版本    yum安装httpd和php    kodexplorer4.25 1 ...

  4. DataSet之增删改查操作(DataGridView绑定)

    DataSet数据集,数据缓存在客户端内存中,支持断开式连接.DataGridView控件绑定DataSet时,它自动的改变的DS的行的状态,而且在做增删改查的时候,可以借助SqlCommandBui ...

  5. [Debug] Diagnose a Slow Page Using Developer Tools

    Your page is showing high CPU usage and spinning up your laptop fan, but nothing is visibly happenin ...

  6. 自己动手写android图片异步载入库

    尊重他人劳动成果,转载请说明出处:http://blog.csdn.net/bingospunky/article/details/44344085 接触android有半年了.关于图片异步载入.一直 ...

  7. OSQL.EXE 命令行下脱裤mssql

    cd C:\Program Files\Microsoft SQL Server\100\Tools\Binn\ OSQL.EXE -S "localhost" -U " ...

  8. ionic准备之angular基础——模板引入(7)

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. Appium Android Bootstrap源代码分析之简单介绍

    在上一个系列中我们分析了UiAutomator的核心源代码,对UiAutomator是怎么执行的原理有了根本的了解.今天我们会開始另外一个在安卓平台上基于UiAutomator的新起之秀--Appiu ...

  10. 乐鑫esp8266的 基于Nonos移植红外线1883,实现遥控器控制

    代码地址如下:http://www.demodashi.com/demo/12613.html 一.前言. 距离上篇的8266进阶博文有那么一段时间了,那么本文带来的是基于Nonos的红外线H1838 ...