public void CreateSchemaCommand()
 {
     try {
         TaskService.Errors.Clear();
         string xml = Editor.Text;
         using (IProgressMonitor monitor = XmlEditorService.GetMonitor()) {
             XmlDocument doc = XmlEditorService.ValidateWellFormedness(monitor, xml, FileName);
             if (doc == null)
             {
                 return;
             }
             monitor.BeginTask(GettextCatalog.GetString("Creating schema..."), 0);
             try {
                 string schema   = XmlEditorService.CreateSchema(Document, xml);
                 string fileName = XmlEditorService.GenerateFileName(FileName, "{0}.xsd");
                 IdeApp.Workbench.NewDocument(fileName, "application/xml", schema);
                 monitor.ReportSuccess(GettextCatalog.GetString("Schema created."));
             } catch (Exception ex) {
                 string msg = GettextCatalog.GetString("Error creating XML schema.");
                 LoggingService.LogError(msg, ex);
                 monitor.ReportError(msg, ex);
             }
         }
     } catch (Exception ex) {
         MessageService.ShowError(ex.Message);
     }
 }
Ejemplo n.º 2
0
        public void RunXslTransformCommand()
        {
            if (string.IsNullOrEmpty(stylesheetFileName))
            {
                stylesheetFileName = XmlEditorService.BrowseForStylesheetFile();
                if (string.IsNullOrEmpty(stylesheetFileName))
                {
                    return;
                }
            }

            using (IProgressMonitor monitor = XmlEditorService.GetMonitor())
            {
                try
                {
                    string xsltContent;
                    try
                    {
                        xsltContent = GetFileContent(stylesheetFileName);
                    }
                    catch (System.IO.IOException)
                    {
                        monitor.ReportError(
                            GettextCatalog.GetString("Error reading file '{0}'.", stylesheetFileName), null);
                        return;
                    }
                    System.Xml.Xsl.XslTransform xslt =
                        XmlEditorService.ValidateStylesheet(monitor, xsltContent, stylesheetFileName);
                    if (xslt == null)
                    {
                        return;
                    }

                    XmlDocument doc = XmlEditorService.ValidateXml(monitor, Editor.Text, FileName);
                    if (doc == null)
                    {
                        return;
                    }

                    string newFileName = XmlEditorService.GenerateFileName(FileName, "-transformed{0}.xml");

                    monitor.BeginTask(GettextCatalog.GetString("Executing transform..."), 1);
                    using (XmlTextWriter output = XmlEditorService.CreateXmlTextWriter(Document))
                    {
                        xslt.Transform(doc, null, output);
                        IdeApp.Workbench.NewDocument(
                            newFileName, "application/xml", output.ToString());
                    }
                    monitor.ReportSuccess(GettextCatalog.GetString("Transform completed."));
                    monitor.EndTask();
                }
                catch (Exception ex)
                {
                    string msg = GettextCatalog.GetString("Could not run transform.");
                    monitor.ReportError(msg, ex);
                    monitor.EndTask();
                }
            }
        }