XmlDocument和XDocument转String
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的更多相关文章
- XmlDocument,XDocument相互转换
XmlDocument,XDocument相互转换 using System; using System.Xml; using System.Xml.Linq; namespace MyTest { ...
- C# -- 使用XmlDocument或XDocument创建xml文件
使用XmlDocument或XDocument创建xml文件 需引用:System.Xml; System.Xml.Linq; 1.使用XmlDocument创建xml(入门案例) static vo ...
- XmlValidationHelper XSD、Schema(XmlSchemaSet)、XmlReader(XmlValidationSettings)、XmlDocument、XDocument Validate
namespace Test { using Microshaoft; using System; using System.Xml; using System.Xml.Linq; class Pro ...
- XmlDocument To String
一.从String xml到XmlDocument的: string xml = "<XML><Test>Hello World</Test></X ...
- XmlDocument.selectNodes() and selectSingleNode()的xpath的学习资料
Xpath网页: http://www.w3school.com.cn/xpath/xpath_syntax.asp XDocument.parse(string)类似于XmlDocument.loa ...
- 七、Linq To XML:XElement、XDocument
一.概述 LINQ to XMLLINQ to XML 是一种启用了 LINQ 的内存 XML 编程接口,使用它,可以在 .NET Framework.NET Framework 编程语言中处理 XM ...
- XML 之 与Json或String的相互转换
1.XML与String的相互转换 [1] XML 转为 String //载入Xml文件 XmlDocument xdoc = new XmlDocument(); xdoc.Load(" ...
- C# 使用XmlDocument类对XML文档进行操作
原创地址:http://www.cnblogs.com/jfzhu/archive/2012/11/19/2778098.html 转载请注明出处 W3C制定了XML DOM标准.很多编程语言中多提供 ...
- C# 操作XML文档 使用XmlDocument类方法
W3C制定了XML DOM标准.很多编程语言中多提供了支持W3C XML DOM标准的API.我在之前的文章中介绍过如何使用Javascript对XML文档进行加载与查询.在本文中,我来介绍一下.Ne ...
随机推荐
- Uncaught SyntaxError: Invalid Unicode escape sequence异常处理
今天碰到一个问题,页面报错:Uncaught SyntaxError: Invalid Unicode escape sequence ,{index:'operate',name:'operate' ...
- Java三大器之过滤器(Filter)的工作原理和代码演示
一.Filter简介 Filter也称之为过滤器,它是Servlet技术中最激动人心的技术之一,WEB开发人员通过Filter技术,对web服务器管理的所有web资源:例如Jsp,Servlet, 静 ...
- python 道生一,一生二,二生三,三生万物
千万不要被所谓“元类是99%的python程序员不会用到的特性”这类的说辞吓住.因为每个中国人,都是天生的元类使用者 学懂元类,你只需要知道两句话: 道生一,一生二,二生三,三生万物 我是谁?我从哪来 ...
- WCF configure
1. maxBufferSize 一个正整数,指定内存中用于存储消息的缓冲区的最大大小(字节). 如果 transferMode 属性等于 Buffered,则此属性应等于 maxReceivedMe ...
- Laravel请求/Cookies/文件上传
一.HTTP请求 1.基本示例:通过依赖注入获取当前 HTTP 请求实例,应该在控制器的构造函数或方法中对Illuminate\Http\Request 类进行类型提示,当前请求实例会被服务容器自动注 ...
- CentOS6安装和卸载docker
系统版本 [root@bogon yum.repos.d]# uname -a Linux bogon 2.6.32-642.el6.x86_64 #1 SMP Tue May 10 17:27:01 ...
- vs无法引用项目问题
vs无法引用项目问题 2017年12月13日 14:45:31 阅读数:582 开发时编译报错--项目A未被引用,展开项目的引用,发现该项目实质已经被引用了,但是该引用上有个黄色三角感叹号,遂移除该引 ...
- C#中的隐藏方法
在C#中要重写基类的方法,C#提倡在基类中使用virtual来标记要被重写的方法,在子类也就是派生类中用voerride关键字来修饰重写的方法. 如果要是项目中前期考虑不足,我没有在基类(ClassA ...
- OpenGL三角形的双面不同颜色的绘制
对于一个三角形,我要给它正反面不同的颜色.然后通过旋转,看出它的效果. 我只想到了2种方法,下面我来写一下这两种方法. 第一种方法,通过角度的判断重设glColor3f的参数(这种方法局限性很大,不推 ...
- The TTY demystified
http://www.linusakesson.net/programming/tty/index.php The TTY demystified Real teletypes in the 1940 ...