サードパーティが解析して電話ナビゲーション システムを提供する VXML プロジェクトがあります。メッセージを残すには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 をそれにフィードしていることは知っていますが、最初に文字列全体を読み取るのはなぜですか? 非効率じゃないですか?
上記のコードを書くためのより良い方法はありますか?