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
Suthish NairPosted Dec 18, 2010, 12:58 AM
mortonPosted Dec 16, 2010, 10:50 AM
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?
FroglegPosted Dec 15, 2010, 9:04 PM
using System.Xml;
XmlTextReader reader = new XmlTextReader("whatever.xml");
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Text)
{
textBox1.AppendText(reader.Value + "\n");
}
}
mortonPosted Dec 15, 2010, 6:45 PM
FroglegPosted Dec 15, 2010, 4:39 PM
textBox1.Text = File.ReadAllText("whatever.xml");
File.WriteAllText("whatever.txt", textBox1.Text);
text settings ? explain