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);

转载于:https://www.cnblogs.com/smartsmile/archive/2012/12/11/6234348.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值