10

メソッドで使用される xmlwriter オブジェクトがあります。これをファイルにダンプして読みたいと思います。これを行う簡単な方法はありますか?

ありがとう

4

2 に答える 2

11

このコードを使用

        // Create the XmlDocument.
        XmlDocument doc = new XmlDocument();
        doc.LoadXml("<item><name>wrench</name></item>");

        // Add a price element.
        XmlElement newElem = doc.CreateElement("price");
        newElem.InnerText = "10.95";
        doc.DocumentElement.AppendChild(newElem);

        // Save the document to a file and auto-indent the output.
        XmlTextWriter writer = new XmlTextWriter(@"C:\data.xml", null);
        writer.Formatting = Formatting.Indented;
        doc.Save(writer);

MSDN にあるとおり: http://msdn.microsoft.com/en-us/library/z2w98a50.aspx

于 2013-03-07T16:31:07.897 に答える
2

1 つの可能性は、テキスト ファイルに出力するように XmlWriter を設定することです。

using (var writer = XmlWriter.Create("dump.xml"))
{
    ...
}
于 2013-03-07T16:31:33.430 に答える