添加System.Xml引用

使用XmlReader转换字符串

DEMO
        #region Parse Xml
private static void ParseXml(string xmlString)
{
StringBuilder output = new StringBuilder();
using(XmlReader reader= XmlReader.Create(new StringReader(xmlString)))
{
reader.ReadToFollowing("book");
reader.MoveToFirstAttribute();
output.AppendLine("The genre value:"+reader.Value);
reader.ReadToFollowing("title");
output.AppendLine("Conten of the title element:"+reader.ReadElementContentAsString()); }
Console.WriteLine(output);
}
#endregion
static void Main(string[] args)
{
#region Parse Xml
String xmlString =
@"<bookstore>
<book genre='autobiography' pubicationdate='1981-3-22' ISBN='1-861003-11-0'>
<title>The Autobiograph of Benamin Franklin</title>
<author>
<first-name>Benjamin</first-name>
<last-name>Franklin</last-name>
</author>
<price>8.99</price>
</book>
</bookstore>";
ParseXml(xmlString);
Console.ReadLine();
#endregion
}

[c# 20问] 2.如何转换XML文件的更多相关文章

  1. c#转换XML文件和json对象

    创建.XML文件string xml = @"<?xml version=""1.0"" standalone=""no&q ...

  2. powershell玩转xml之20问

    powershell玩转xml之20问 powershell 传教士 原创文章 2014-01-30,2015-10-27改 允许转载,但必须保留名字和出处,否则追究法律责任 问:xml文件编码情况如 ...

  3. C#中如何创建xml文件 增、删、改、查 xml节点信息

    XML:Extensible Markup Language(可扩展标记语言)的缩写,是用来定义其它语言的一种元语言,其前身是SGML(Standard Generalized Markup Lang ...

  4. 在java代码中用xslt处理xml文件

    java处理xml文件 import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundExceptio ...

  5. 20170319 ABAP 生成XML文件

    方法一:ABAP 使用method方式操作XML 转自:http://www.cnblogs.com/jiangzhengjun/p/4265595.html 方法二:STRANS 转换工具;使用st ...

  6. XML文件与实体类的互相转换

    XML文件与实体类的互相转换 一.将XML文件反序列化为实体类对象 1. 通常程序的配置信息都保存在程序或者网站的专门的配置文件中(App.config/web.config).但是现在为了演示XML ...

  7. android XMl 解析神奇xstream 五: 把复杂对象转换成 xml ,并写入SD卡中的xml文件

    前言:对xstream不理解的请看: android XMl 解析神奇xstream 一: 解析android项目中 asset 文件夹 下的 aa.xml 文件 android XMl 解析神奇xs ...

  8. DataSet与Xml文件的互相转换

    DataSet转换为xml文件   //将DataSet转换为xml文件        private static void ConvertDataSetToXMLFile(DataSet xmlD ...

  9. json串转化成xml文件、xml文件转换成json串

    1.json串转化成xml文件 p=[{"name":"tom","age":30,"sex":"男" ...

随机推荐

  1. mysql-12序列使用

    mysql序列是一组整数:1,2,3....,由于一张数据表只能有一个字段自增主键,如果你想实现其他字段自动增加,就可以使用mysql序列来实现. 使用auto_increment来定义列 drop ...

  2. VS2017如何配置openGL环境

    转自:http://blog.csdn.net/qq_26982531/article/details/62056913 这里着重介绍vs2017配置openGL环境与以前版本的不同之处:       ...

  3. 需登录账号与密码的网页爬取demo

    public static String connect(String dataUrl){ String result = null; try { HttpClient httpclient = ne ...

  4. tensorflow-base_operations

    # -*- coding: utf-8 -*-import tensorflow as tf# 基本的常量操作,通过构造函数返回值 定义值的操作operationsa = tf.constant(2) ...

  5. probably another instance of uWSGI is running on the same address (127.0.0.1:9090). bind(): Address already in use

    probably another instance of uWSGI is running on the same address (127.0.0.1:9090). bind(): Address ...

  6. leetcode28

    public class Solution { public int StrStr(string haystack, string needle) { return haystack.IndexOf( ...

  7. PHP环境 PDOException PDOException: could not find driver

    PDOException PDOException: could not find driver in dbcon.php:29 修改php.ini文件中的相关内容.对于找不到php.ini证明你的p ...

  8. 你真的了解lambda吗?一文让你明白lambda用法与源码分析

    本文作者: cmlanche 本文链接: http://www.cmlanche.com/2018/07/22/lambda用法与源码分析/ 转载来源:cmlanche.com 用法 示例:最普遍的一 ...

  9. padding margin border 和元素大小

    元素占用宽度 = 元素宽度+padding+border+margin 注意margin只是隔开元素,不会使得元素变大,而padding会使得元素变大,也就是说 元素真实宽度=元素宽度+padding ...

  10. es6 class 了解

    ES6之class ES5中通常通过构造函数和原型的组合形式来创建对象.在ES6中引入class作为对象模板, Class定义语法 class point{ constructor(x,y){ thi ...