用response输出XML

直接在代码中组织xml:   

string strXML = "<?xml version=/"1.0/"?>";
                strXML+="<books><bookdata id=/"1/">";
           
     strXML+="<title>C# premier</title>";
     strXML += "<year>2005</year>";
     strXML+="<publisher> Qinghua University Press</publisher>";
     strXML+="<Author>hou </Author>";
     strXML+="<pagers>500 </pagers>";
     strXML+="<description> c# fundation knowledge</description>";
     strXML+="<Price>50.00</Price>";
   strXML+="</bookdata>";

   strXML+="<bookdata id=/"2/">";
     strXML+="<title>xml premier</title>";
     strXML+="<year>2005</year>";
     strXML+="<publisher> Peking University Press</publisher>";
     strXML+="<Author>Leo </Author>";
     strXML+="<pagers>400 </pagers>";
     strXML+="<description> xml fundation knowledge</description>";
     strXML+="<Price>45.00</Price>";
  strXML+="</bookdata>";

   strXML+="<bookdata id=/"3/">";
     strXML+="<title>UML</title>";
     strXML+="<year>2005</year>";
     strXML+="<publisher> Peking University Press</publisher>";
    strXML+=" <Author>James </Author>";
    strXML+=" <pagers>650 </pagers>";
    strXML+=" <description>UML fundation knowledge</description>";
    strXML += " <Price>85.00</Price>";
  strXML+=" </bookdata></books>";

            Response.ContentType = "text/xml";
            Response.Charset = "UTF-8";
            System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
            doc.LoadXml(strXML);
            doc.Save(Response.OutputStream);
            Response.End();

读取现有的xml:

 Response.ContentType = "text/xml";
            Response.Charset = "UTF-8";
            System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
            string strPath = @"~/login/xmlfile";
            doc.Load(Server.MapPath(strPath + "/books.xml"));//requests.xml是服务器上xml文件   
            Response.Write(doc.DocumentElement.OuterXml);   
             Response.End();

 
  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值