i need to read in a XML in a textbox (maybe richtextbox?).
Here´s a snippet of XML:
doc.xml
|
I want to show the text inside the textbox with it`s exact format.
My questions:
1. How can i read in the text-content of the XML and display it in a textbox?
2. Is it possible to read in the text-settings as well and how can i do that?
(3. Some idea for saving this XML from that textbox?)
thank you,
morton

FroglegRank #1,020 · 1.9K reputationPosted Dec 15, 2010, 11:39 AM EST
textBox1.Text = File.ReadAllText("whatever.xml");
File.WriteAllText("whatever.txt", textBox1.Text);
text settings ? explain
morton5 reputationPosted Dec 15, 2010, 1:45 PM EST
FroglegRank #1,020 · 1.9K reputationPosted Dec 15, 2010, 4:04 PM EST
using System.Xml;
XmlTextReader reader = new XmlTextReader("whatever.xml");
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Text)
{
textBox1.AppendText(reader.Value + "\n");
}
}
morton5 reputationPosted Dec 16, 2010, 5:50 AM EST
Here´s the code:
{
InitializeComponent();
Uri url = new Uri("doc.xml", UriKind.Relative);
WebClient client = new WebClient();
client.OpenReadCompleted += new OpenReadCompletedEventHandler(client_OpenReadCompleted);
client.OpenReadAsync(url)
}
private void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
if (e.Error != null)
{
MessageBox.Show(e.Error.ToString());
return;
}
using (System.IO.Stream s = e.Result)
{
System.Xml.Linq.XDocument doc = System.Xml.Linq.XDocument.Load(s);
var simpleQuery = from simpleItem in doc.Descendants("doc")
select simpleItem;
foreach (System.Xml.Linq.XElement element in simpleQuery)
{
richTextBox1.Selection.Text = richTextBox1.Selection.Text + element.Value;
}
}
}
My next questions, how can i get the text with the right style-settings (fonts,size etc.)?
And how to set the text in the correct line?
Suthish NairRank #92 · 22.8K reputationPosted Dec 17, 2010, 7:58 PM EST