zoukankan      html  css  js  c++  java
  • asp.net读取Xml文件到DataSet,以及DataSet保存为Xml,利用自带的强大功能

    <music>
      <song>
        <artist>The Chi-lites</artist>
        <genre>Soul</genre>
        <album>A lonely man</album>
        <year>1972</year>
      </song>
      <song>
        <artist>Babyface</artist>
        <genre>R&B</genre>
        <album>unknown</album>
        <year></year>
      </song>
      <song>
        <artist>Babyface</artist>
        <genre>R&B</genre>
        <album>The essential babyface</album>
        <year>2001</year>
      </song>
      <song>
        <artist>Babyface</artist>
        <genre>R&B</genre>
        <album>Grown and sexy</album>
        <year>2005</year>
      </song>
      <song>
        <artist>Maria Arredondo</artist>
        <genre>Pop</genre>
        <album>Not going under</album>
        <year>2004</year>
      </song>
      <song>
        <artist>Leona Lewis</artist>
        <genre>Pop</genre>
        <album>Unknown</album>
        <year>2008</year>
      </song>
      <song>
        <artist>Usher</artist>
        <genre>R&B</genre>
        <album>Usher</album>
        <year>2008</year>
      </song>
      <song>
        <artist>Christina Aguilera</artist>
        <genre>Blues</genre>
        <album>Back to basics</album>
        <year>2004</year>
      </song>
      <song>
        <artist>Sting</artist>
        <genre>Pop</genre>
        <album>Shape of my heart</album>
        <year></year>
      </song>
    </music>
                DataSet ds = new DataSet();
                TextReader reader = new StringReader(@"
                            <music>
                              <song>
                                <artist>The Chi-lites</artist>
                                <genre>Soul</genre>
                                <album>A lonely man</album>
                                <year>1972</year>
                              </song>
                              <song>
                                <artist>Babyface</artist>
                                <genre>R&B</genre>
                                <album>unknown</album>
                                <year></year>
                              </song>
                              <song>
                                <artist>Babyface</artist>
                                <genre>R&B</genre>
                                <album>The essential babyface</album>
                                <year>2001</year>
                              </song>
                              <song>
                                <artist>Babyface</artist>
                                <genre>R&B</genre>
                                <album>Grown and sexy</album>
                                <year>2005</year>
                              </song>
                              <song>
                                <artist>Maria Arredondo</artist>
                                <genre>Pop</genre>
                                <album>Not going under</album>
                                <year>2004</year>
                              </song>
                              <song>
                                <artist>Leona Lewis</artist>
                                <genre>Pop</genre>
                                <album>Unknown</album>
                                <year>2008</year>
                              </song>
                              <song>
                                <artist>Usher</artist>
                                <genre>R&B</genre>
                                <album>Usher</album>
                                <year>2008</year>
                              </song>
                              <song>
                                <artist>Christina Aguilera</artist>
                                <genre>Blues</genre>
                                <album>Back to basics</album>
                                <year>2004</year>
                              </song>
                              <song>
                                <artist>Sting</artist>
                                <genre>Pop</genre>
                                <album>Shape of my heart</album>
                                <year></year>
                              </song>
                            </music>
                            ");
                //读取Xml字符串 用来接收WebService返回数据
                //ds.ReadXml(reader, XmlReadMode.Auto);
    
                //读取Xml文件
                ds.ReadXml(Server.MapPath("XML/Song.xml"));
    
                //生成Xml文件
                //ds.WriteXml(Server.MapPath("xml/song_bak.xml"));
                GridView1.DataSource = ds;
                GridView1.DataBind();

                //读取txt文件
                Stream stream = new FileStream(Server.MapPath("XML/demo.txt"), FileMode.OpenOrCreate, FileAccess.Read);
                StreamReader readStream = new StreamReader(stream, System.Text.Encoding.GetEncoding("GB2312"));
                string SourceCode = readStream.ReadToEnd();
                readStream.Close();
                Response.Write(SourceCode);

  • 相关阅读:
    Oracle创建表空间用户等
    centos7安装neo4j
    Linux 介绍和命令超详细
    Go 变量声明
    Manjaro 安装 & 配置
    Go Golang安装及环境变量配置
    python3集合与常用操作
    正则以及re库的使用
    Requests 库安装
    数据库-数据库管理系统-数据库系统
  • 原文地址:https://www.cnblogs.com/smartsmile/p/6234348.html
Copyright © 2011-2022 走看看