【发布时间】:2010-09-14 08:32:28
【问题描述】:
我们有一个 VXML 项目,第 3 方对其进行解析以向我们提供电话导航系统。我们要求他们输入一个 ID 码来留言,我们公司稍后会对其进行审核。
我们目前的工作如下:
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Stream m = new MemoryStream(); //Create Memory Stream - Used to create XML document in Memory
XmlTextWriter XML_Writer = new XmlTextWriter(m, System.Text.Encoding.UTF8);
XML_Writer.Formatting = Formatting.Indented;
XML_Writer.WriteStartDocument();
/* snip - writing a valid XML document */
XML_Writer.WriteEndDocument();
XML_Writer.Flush();
m.Position = 0;
byte[] b = new byte[m.Length];
m.Read(b, 0, (int)m.Length);
XML_Writer.Close();
HttpContext.Current.Response.Write(System.Text.Encoding.UTF8.GetString(b, 0, b.Length));
我只是在维护这个应用程序,不是我写的……但结尾部分对我来说似乎很复杂。
我知道它正在获取输出流并将写入的 XML 输入其中...但是为什么它首先读取整个字符串?这不是效率低吗?
上面的代码有没有更好的写法?
【问题讨论】:
标签: asp.net stream xmltextwriter