public static string CreateSchema(TextEditor doc, string xml) { using (var dataSet = new System.Data.DataSet()) { dataSet.ReadXml(new StringReader(xml), System.Data.XmlReadMode.InferSchema); using (var writer = new EncodedStringWriter(Encoding.UTF8)) { using (var xmlWriter = CreateXmlTextWriter(doc, writer)) { dataSet.WriteXmlSchema(xmlWriter); return(writer.ToString()); } } } }
public static string CreateSchema(Document doc, string xml) { using (System.Data.DataSet dataSet = new System.Data.DataSet()) { dataSet.ReadXml(new StringReader(xml), System.Data.XmlReadMode.InferSchema); using (EncodedStringWriter writer = new EncodedStringWriter(Encoding.UTF8)) { using (XmlTextWriter xmlWriter = XmlEditorService.CreateXmlTextWriter(doc, writer)) { dataSet.WriteXmlSchema(xmlWriter); return(writer.ToString()); } } } }
public void RunXslTransformCommand() { if (string.IsNullOrEmpty(stylesheetFileName)) { stylesheetFileName = XmlEditorService.BrowseForStylesheetFile(); if (string.IsNullOrEmpty(stylesheetFileName)) { return; } } using (ProgressMonitor monitor = XmlEditorService.GetMonitor()) { try { string xsltContent; try { xsltContent = GetFileContent(stylesheetFileName); } catch (IOException) { monitor.ReportError( GettextCatalog.GetString("Error reading file '{0}'.", stylesheetFileName), null); return; } (var xslt, var errors) = XmlEditorService.CompileStylesheet(xsltContent, stylesheetFileName); if (xslt == null) { monitor.ReportError(GettextCatalog.GetString("Failed to compile stylesheet")); return; } string newFileName = XmlEditorService.GenerateFileName(FileName, "-transformed{0}.xml"); monitor.BeginTask(GettextCatalog.GetString("Executing transform..."), 1); var output = new EncodedStringWriter(Encoding.UTF8); using (XmlReader input = XmlReader.Create(new StringReader(Editor.Text), null, FileName)) { using (XmlTextWriter writer = XmlEditorService.CreateXmlTextWriter(Editor, output)) { xslt.Transform(input, writer); } } 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(); } } }