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. 自己定义JSTL函数

    因为 jstl 函数 字符串替换不支持正則表達式 所以想用java String的 replaceAll进行替换 须要自己定义 jstl函数 首先写类 package com.salesmanb2b. ...

  2. Hadoop之Mapreduce详解

    1. 什么是Mapreduce  Mapreduce是一个分布式运算程序的编程框架,是用户开发“基于hadoop的数据分析应用”的核心框架: Mapreduce核心功能是将用户编写的业务逻辑代码和自带 ...

  3. Angular 学习笔记——$http

    <!DOCTYPE HTML> <html ng-app="myApp"> <head> <meta http-equiv="C ...

  4. cmake 生成VS项目文件夹

    SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON) SET_TARGET_PROPERTIES(test_tcp_client test_tcp_server P ...

  5. mongoDB - 插入数据

    db.use.js /** * 使用前:先安装node环境.express.mongodb. * * 1.1 安装Node * 1.2 npm i -D express mongodb &&a ...

  6. wps文档忘记保存关闭了怎么恢复

    wps文档忘记保存关闭了怎么恢复 点击程序左上角的''WPS文字/表格/演示''选择备份管理,根据需要尝试右侧下面的"查看其他备份"功能就能找了. 点击"开始-运行&qu ...

  7. [译] 回调地狱——JavaScript异步编程指南

    原文:Callback Hell 什么是 “回调地狱”? 在 JavaScript 中,我们经常通过回调来实现异步逻辑,一旦嵌套层级多了,代码结构就容易变得很不直观,最后看起来像这样: fs.read ...

  8. git 4种对象的理解

    git中有四种基本对象类型,可以说Git的所有操作都是通过这四种对象完成的.下图是<Git版本控制管理>中文第二版的原话,顺便吐槽一下,这本书真的翻译的一般.. 下面说下我的理解吧,首先b ...

  9. 一个可以模拟GET,POST,PUT,DELET请求的HTTP在线工具

    一个简陋的HTTP请求工具,UI比较丑陋.0.0,可以用于接口调试. 之前在调试公司的远程接口的时候用的是curl,后来也在网上找到几种Http请求模拟的客户端程序.当时后来发现google app ...

  10. 用Python抓取漫画并制作mobi格式电子书

    想看某一部漫画,但是用手机看感觉屏幕太小,用电脑看吧有太不方面.正好有一部Kindle,决定写一个爬虫把漫画爬取下来,然后制作成 mobi 格式的电子书放到kindle里面看. 一.编写爬虫程序 用C ...