逐行读取XML [英] Read XML Line by Line
问题描述
我想知道如何制作它以便当我使用MultiLine textBox时它会识别出有多行!
以下是我用Open File Dialog打开它们的方法:
I am wondering how one would make it so that when I use MultiLine textBox it will recognize that there is multiple lines!
Here is how I am opening them with Open File Dialog:
OpenFileDialog ofd2 = new OpenFileDialog();
if (ofd2.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
XmlSerializer xs = new XmlSerializer(typeof(Information));
FileStream read = new FileStream(ofd2.FileName, FileMode.Open, FileAccess.Read, FileShare.Read);
Information info = (Information)xs.Deserialize(read);
textBox1.Text = info.Notes;
}
}
这就是我暂时保存它们的方式:
This is how I am saving them for the time being:
SaveFileDialog sfd = new SaveFileDialog();
sfd.Title = "Save File";
if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
try
{
Information info = new Information();
info.Notes= textBox1.Text;
SaveXML.SaveData(info, sfd.FileName + ".xml");
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
希望有人可以帮我这样做更好的方法或解释我怎么能得到剧本的开头部分才能认出他们已经进入剧本...
我一直在看我用的其他程序其他人写的C#和我注意到的一件事是当你保存其中一个程序时它会让你多行文本框有一个;一旦你点击进入,不知何故它会在程序开启时重新识别这个,也许我们可以弄清楚如何做到这一点?
谢谢,GOOBER。
Hopefully someone can help me do this a better way or explain to me how I can get the opening part of the script to recognize that their are enters in the script...
I have been looking at other programs I use made from C# that others have written and one thing I noticed is when you save on one of the programs it would make you multiline textbox have a ";" after time you hit enter and somehow it would rexognize this on opening of the program, maybe we could figure out how to do this?
Thanks, GOOBER.
推荐答案
我建议您使用RichTextBox而不是多行TextBox。您是否考虑过修改算法以使用XmlWriter,XmlWriterSettings和StringBuilder? XmlWriterSettings可以使您的XML可读。
May I suggest that you use a RichTextBox rather than a multi-line TextBox. Have you considered revising your algorithm to use XmlWriter, XmlWriterSettings, and StringBuilder? The XmlWriterSettings can make your XML human readable.
这篇关于逐行读取XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!