zoukankan      html  css  js  c++  java
  • ASP.Net输出纯XML数据

    有时asp.net文件输出纯XML数据很有用,这时的asp.net文件就相当于一个WebService,输出XML文档也很简单,分以下几部
    1、设置输出类型-Response.ContentType = "text/xml";
    2、设置字符集-Response.Charset = "GB2312";
    3、清空输入内容-Response.Clear();
    4、构造XML内容并输出-Response.Write(...)
    最后结束余下的输出Response.End(),

    DataSet ds = new DataSet();
    DataTable table = new DataTable("Item");
    table.Columns.Add("Name", typeof(string));
    table.Columns.Add("Price", typeof(string));

    DataRow r = table.NewRow();
    r[0] = "huzhen";
    r[1] = "huzhen";
    table.Rows.Add(r);

    r = table.NewRow();
    r[0] = "huzhen";
    r[1] = "huzhen";
    table.Rows.Add(r);

    ds.Tables.Add(table);
    Response.ContentType = "text/xml";
    Response.Charset = "GB2312";
    Response.Clear();
    Response.Write("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n " + ds.GetXml());
    Response.End();

  • 相关阅读:
    Eclipse 添加行号
    http中 get方法 传送中文参数乱码解决办法
    第一章 java 语言概述
    Python学习
    Python学习
    Python学习
    Python学习
    Python学习
    Python学习
    Python学习
  • 原文地址:https://www.cnblogs.com/xinzhuangzi/p/4100726.html
Copyright © 2011-2022 走看看