xmlファイル(ansi)を開いて、UTF-8に変換して保存しようとしています。
これが私のコードです:
using System;
using System.IO;
using System.Text;
using System.Xml;
class Test
{
public static void Main()
{
string path = @"C:\test\test.xml";
string path_new = @"C:\test\test_new.xml";
try
{
XmlTextReader reader = new XmlTextReader(path);
XmlWriterSettings settings = new XmlWriterSettings();
settings.Encoding = new UTF8Encoding(false);
using (var writer = XmlWriter.Create(path_new, settings))
{
reader.Save(writer);
}
}
catch (Exception e)
{
Console.WriteLine("The process failed: {0}", e.ToString());
}
}
}
「System.Xml.XmlTextReader」に「Save」の定義が含まれておらず、「System.Xml.XmlTextReader」タイプの最初の引数を受け入れる拡張メソッド「Save」が見つからないというエラーが発生します(ディレクティブまたはアセンブリ参照を使用しますか?)
ここで欠けているクラスは何ですか?私のコードは仕事をするのに正しいですか
編集:
さて、ここで私に例外を与えている別のコード:
using System;
using System.IO;
using System.Text;
using System.Xml;
class Test
{
public static void Main()
{
string path = @"C:\project\rdsinfo.xml";
//string path_new = @"C:\project\rdsinfo_new.xml";
try
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(path);
}
catch (Exception e)
{
Console.WriteLine("The process failed: {0}", e.ToString());
}
}
}
それは私に例外、与えられたエンコーディングの無効な文字を与えています。