private void Main_DragDrop(object sender, DragEventArgs e) { string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); foreach (string fileName in files) { string text = File.ReadAllText(fileName.ToString()); TranForm newChildForm; if (fileName.EndsWith("xsl")) { newChildForm = new XSLForm(); } else { newChildForm = new XMLForm(); } // Set the Parent Form of the Child window. newChildForm.MdiParent = this; // Display the new form. newChildForm.Show(); newChildForm.TextEditor.Text = text; newChildForm.Text = fileName.ToString(); newChildForm.Dirty = false; } }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog theDialog = new OpenFileDialog(); theDialog.Title = "Open Text File"; theDialog.Filter = "XML files|*.xml;*.xsl;*.xslt;*.xsd|All files|*.*"; if (theDialog.ShowDialog() == DialogResult.OK) { string text = File.ReadAllText(theDialog.FileName.ToString()); TranForm newChildForm; if (theDialog.FileName.EndsWith("xsl")) { newChildForm = new XSLForm(); } else { newChildForm = new XMLForm(); } // Set the Parent Form of the Child window. newChildForm.MdiParent = this; // Display the new form. newChildForm.Show(); newChildForm.TextEditor.Text = text; newChildForm.Text = theDialog.FileName.ToString(); newChildForm.Dirty = false; } }
private void tsmNewXML_Click(object sender, EventArgs e) { XMLForm newMDIChild = new XMLForm(); // Set the Parent Form of the Child window. newMDIChild.MdiParent = this; // Display the new form. newMDIChild.Show(); }
private void Transform() { var processor = new Processor(); XsltCompiler compiler = processor.NewXsltCompiler(); XMLForm frmXML = null; XSLForm frmXSL = null; try { Cursor.Current = Cursors.WaitCursor; // Find the XSL form and XML forms foreach (Form frm in this.MdiChildren) { if (frm.Tag == null) { if (frm.Name == "XMLForm") { frmXML = (XMLForm)frm; } else if (frm.Name == "XSLForm") { frmXSL = (XSLForm)frm; } } } if (frmXML == null) { throw new ApplicationException("No XML form found"); } if (frmXSL == null) { throw new ApplicationException("No XSL form found"); } if (frmXSL.TextEditor.Text == "") { throw new ApplicationException("XSL form is empty"); } if (frmXML.TextEditor.Text == "") { throw new ApplicationException("XML form is empty"); } TextReader xslReader = new StringReader(frmXSL.TextEditor.Text); // Compile stylesheet XsltExecutable executable = compiler.Compile(xslReader); // Do transformation to a destination RawDestination destination = new RawDestination(); using (MemoryStream xmlStream = new MemoryStream(Encoding.UTF8.GetBytes(frmXML.TextEditor.Text ?? ""))) { Xslt30Transformer transformer = executable.Load30(); transformer.ApplyTemplates(xmlStream, destination); } string result; if (this.indentResultToolStripMenuItem.Checked) { // Indent the XML var stringBuilder = new StringBuilder(); var element = XElement.Parse(destination.XdmValue.ToString()); var settings = new XmlWriterSettings(); settings.OmitXmlDeclaration = false; settings.Indent = true; settings.NewLineOnAttributes = false; using (var xmlWriter = XmlWriter.Create(stringBuilder, settings)) { element.Save(xmlWriter); } result = stringBuilder.ToString(); } else { result = destination.XdmValue.ToString(); } // Get / create the form XMLForm frmResult = null; if (this.overwriteOutputToolStripMenuItem.Checked) { foreach (Form frm in this.MdiChildren) { if (frm.Tag != null) { if (frm.Tag.ToString() == "Output") { frmResult = (XMLForm)frm; break; } } } } // If form has not been got then create it if (frmResult == null) { frmResult = new XMLForm(); frmResult.Owner = this; } else { frmResult.TopMost = true; frmResult.BringToFront(); } frmResult.MdiParent = this; frmResult.TextEditor.Text = result; frmResult.Tag = "Output"; frmResult.Show(); } catch (Exception ex) { string err = ex.Message + "\n"; err += ex.GetType().ToString() + "\n"; foreach (StaticError staticErr in compiler.ErrorList) { err += staticErr.Message + " (line no : " + staticErr.LineNumber + ")\n"; } MessageBox.Show(err); } finally { Cursor.Current = Cursors.Default; } }