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 ...
随机推荐
- HTML5 Canvas 动态勾画等速螺线
等速螺线亦称阿基米德螺线,得名于公元前三世纪希腊数学家阿基米德.阿基米德螺线是一个点匀速离开一个固定点的同时又以固定的角速度绕该固定点转动而产生的轨迹.在此向这位古代最伟大的数学家致敬.用Canvus ...
- MySQL的左外连接
代码: select t1.descid, IFNULL(t2.cnt,) as countnew, t1.description from uosdesc t1 left outer join t2 ...
- InternalNative.cpp
1 /* * Copyright (C) 2008 The Android Open Source Project * * Licensed under the Apache License, Ver ...
- Visual Prolog 的 Web 专家系统 (10)
GENI的核心 -- 推理机(4)求证过程分析 1.GENI知识库结构 专家系统推理机的设计执行,与其知识库结构紧密相关. GENI知识库结构是一棵逻辑推理树. 根节点是animal,即求证的目标. ...
- Nginx探索三
这次探索一下http 请求 request 这节我们讲request,在nginx中我们指的是http请求,详细到nginx中的数据结构是ngx_http_request_t. ngx_http_re ...
- uva507 - Jill Rides Again(最长连续和)
option=com_onlinejudge&Itemid=8&page=show_problem&problem=448">题目:uva507 - Jill ...
- chown将指定文件的拥有者改为指定的用户或组(转)
chown将指定文件的拥有者改为指定的用户或组,用户可以是用户名或者用户ID:组可以是组名或者组ID:文件是以空格分开的要改变权限的文件列表,支持通配符.系统管理员经常使用chown命令,在将文件拷贝 ...
- CentOS6.8 搭建SVN并用钩子自动实现同步到web目录
一 安装 yum install subversion 二 检查是否安装成功 svn --version 三 创建仓库目录 mkdir –p /home/svnroot/test 四 创建项目 svn ...
- TortoiseGit 连接oschina不用每次输入username和password的方法
每次git clone 和push 都要输入username和password.尽管安全.但在本机上每次都输有些麻烦,怎样记住username和password呢? 在网上看了各种方法,太杂,非常多可 ...
- linux系统下面ftp的一些命令
service vsftpd restart重启vsftpd服务service vsftpd stop停止vsftpd服务service vsftpd start启动vsftpd服务 chkconfi ...