private void toolStripMenuItem13_Click(object sender, EventArgs e)
{
this.xmlTreeView1.CancelEdit();
//Save the text form clipboard as file
string rawXml = Clipboard.GetText();
//Validate the XML data
XmlDocument xd = new XmlDocument();
try
{
//Remove <?xml> declaration
if (rawXml.StartsWith("<?xml version"))
rawXml =
System.Text.RegularExpressions.Regex.Replace(
rawXml, "[<][?]xml.+?[?]>", "");
if (!rawXml.StartsWith("<"))
rawXml = rawXml.Substring(rawXml.IndexOf("<"));
//Use LoadXml to test if the XML is valid
xd.LoadXml(rawXml);
//Save it as a temp file
string fileName = System.IO.Path.GetTempFileName() + ".xml";
File.WriteAllText(fileName, Clipboard.GetText());
//Call internal method to open the file
InternalOpen(fileName);
}
catch (Exception ex)
{
MessageBox.Show("Invliad XML document.");
}
}
private void toolStripMenuItem14_Click(object sender, EventArgs e)
{
//Commit changes
this.xmlTreeView1.Commit();
//Prepare the XmlTextWriter
MemoryStream ms = new MemoryStream();
XmlTextWriter xtw = new XmlTextWriter(ms, Encoding.UTF8);
xtw.Formatting = Formatting.Indented;
//Dump XML to the XmlTextWriter
this.model.Document.Save(xtw);
xtw.Flush();
xtw.Close();
//Send it to the clipboard
Clipboard.SetText(Encoding.UTF8.GetString(ms.ToArray()));
}