.csvファイルに基づいてXMLファイルを作成しようとしています。 .csvファイルを読み込み、一部の部分を置き換えるために私の古い方法を使うことができると思った。しかし、私が言った例外を取得:C#Linq XML InvalidOperationException
InvalidOperationExceptionがここ
は私のコードは次のとおりです。
public void LoadFile() {
XDocument outputDocument = new XDocument();
outputDocument.Add(new XElement("Inventory"));
using (var fstream = File.OpenRead(FilePathProducts))
using (var fileReader = new StreamReader(fstream)) {
while (!fileReader.EndOfStream) {
var readLine = fileReader.ReadLine();
var words = readLine.Split(';');
outputDocument.Add(
new XElement("Item",
new XElement("Name", words[1]),
new XElement("Count", words[3]),
new XElement("Price", words[4]),
new XElement("Comment", "<Missing Value>"),
new XElement("Artist", "<Missing Value>"),
new XElement("Publisher", "Nintendo"),
new XElement("Genre", "<Missing Value>"),
new XElement("Year", words[0]),
new XElement("ProductID", words[2])
)
);
}
}
outputDocument.Save(FilePathResult);
}
これは(おおよその翻訳。) "不当に構造化文書が作成された" について何かを言う
ループを削除しようとすると、出力ファイルに自己閉鎖インベントリタグしか表示されませんでした。私はそれがオープンでクローズドタグであることを期待していました。だから、私は上記のコードの3行目で何かが間違っていると推測しています。
ヒント:// WWW:あなたは、[ローカライズされたエラーメッセージ検索](httpsを使用することができますMicrosoft.com/Language/ja-US/Emt.aspx)を使用して、エラーメッセージを言語から英語に翻訳します。 – Default