1.XmlDocument类或XDocument类中有没有什么成员可以设置xml文档的样式文件,即xml文档内容的第二行有<?xml-stylesheet type="text/xsl" href="xsl样式文件"?>2.生成xml除了context.Response.Write(xmlDoc.ToString());还有什么方法,我用xmlDoc.WriteTo(XmlWriter.Create(context.Response.OutputStream));为什么没有用

解决方案 »

  1.   

    也可以自己用StreamWriter勒、节点等可以通过循环输出、string _xmlFileName = "index_banner_550x150.xml";
                    string path = string.Empty;
                    path = Server.MapPath("~/community/xml/" + _xmlFileName);
                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }
                    StreamWriter sw = File.CreateText(path);
                    try
                    {
                        sw.WriteLine();                    sw.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
                        sw.WriteLine("<time>2</time>");
                        sw.WriteLine("<type>4</type>");                    foreach (Model.AdService adServiceModel in adServiceModels)
                        {
                            sw.WriteLine("<step>");
                            sw.WriteLine(string.Format("    <img>{0}{1}</img>", this.UploadFileVAds, adServiceModel.AdIMG));
                            sw.WriteLine(string.Format("    <url>{0}</url>", "http://" + adServiceModel.AdURL));
                            sw.WriteLine("    <tar>_blank</tar>");
                            sw.WriteLine("</step>");
                        }                }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message);
                    }
                    finally
                    {
                        sw.Flush();
                        sw.Close();
                    }
                }
      

  2.   

    ???
    我只是想把生成好了的xml文档写入到网页输出流,xmlDoc.WriteTo(XmlWriter.Create(context.Response.OutputStream))哪里有问题啊