private void CreateCourseDom() { var d = new DomDocument<Manifest>(); ADL.SCORM.Namespaces.LoadNamespaceMappings(d); pMessages = new UserMessageCollection(); if (d.Load(this.pMessages, this.pManifestFileInfo)) { this.pManifest = d.DocumentElement; } else { throw new ApplicationException("The imsmanifet that was selected could not be loaded."); } }
private void CreateCourseDom() { var d = new DomDocument <Manifest>(); ADL.SCORM.Namespaces.LoadNamespaceMappings(d); pMessages = new UserMessageCollection(); if (d.Load(this.pMessages, this.pManifestFileInfo)) { this.pManifest = d.DocumentElement; } else { throw new ApplicationException("The imsmanifet that was selected could not be loaded."); } }
private void mXML2RTF_Click(object sender, EventArgs e) { MessageBox.Show("Conver a xml to rtf file"); string sourceFileName = null; string descFileName = null; using (OpenFileDialog dlg = new OpenFileDialog()) { dlg.Filter = "*.xml|*.xml"; dlg.CheckFileExists = true; dlg.ShowReadOnly = false; if (dlg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) { sourceFileName = dlg.FileName; } else { return; } } using (SaveFileDialog dlg = new SaveFileDialog()) { dlg.Filter = "RTF文件(*.rtf)|*.rtf"; dlg.CheckPathExists = true; dlg.OverwritePrompt = true; if (dlg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) { descFileName = dlg.FileName; } else { return; } } DomDocument document = new DomDocument(); document.Load(sourceFileName, FileFormat.XML); using (System.Drawing.Graphics g = document.CreateGraphics()) { document.RefreshSize(g); document.ExecuteLayout(); document.RefreshPages(); document.Save(descFileName, FileFormat.RTF); } MessageBox.Show(string.Format("success convert xml file'{0}' to rtf file'{1}'", sourceFileName, descFileName)); }
protected void InsertHtml(object sender, WriterCommandEventArgs args) { if (args.Mode == WriterCommandEventMode.QueryState) { args.Enabled = args.DocumentControler != null && args.Document != null && args.DocumentControler.CanInsertElementAtCurrentPosition( typeof(DomElement)); } else if (args.Mode == WriterCommandEventMode.Invoke) { args.Result = false; DomDocument document = null; if (args.Parameter is string) { System.IO.StringReader reader = new System.IO.StringReader( (string)args.Parameter); document = (DomDocument)System.Activator.CreateInstance(args.Document.GetType()); DocumentLoader.LoadHtmlFile(reader, document, null); reader.Close(); } else if (args.Parameter is System.IO.Stream) { document = (DomDocument)Activator.CreateInstance(args.Document.GetType()); document.Load((System.IO.Stream)args.Parameter, FileFormat.Html); } else if (args.Parameter is System.IO.TextReader) { document = (DomDocument)System.Activator.CreateInstance(args.Document.GetType()); DocumentLoader.LoadHtmlFile((System.IO.TextReader)args.Parameter, document, null); } if (document != null && document.Body != null && document.Body.Elements.Count > 0) { DomElementList list = document.Body.Elements; args.Document.ImportElements(list); args.DocumentControler.InsertElements(list); args.Result = list; } } }
protected void InsertFileContent(object sender, WriterCommandEventArgs args) { if (args.Mode == WriterCommandEventMode.QueryState) { args.Enabled = args.DocumentControler != null && args.Document != null && args.DocumentControler.CanInsertElementAtCurrentPosition( typeof(DomElement)); } else if (args.Mode == WriterCommandEventMode.Invoke) { args.Result = false; DomDocument document = null; string fileName = null; if (args.Parameter is string) { fileName = (string)args.Parameter; } else if (args.Parameter is DomDocument) { document = (DomDocument)args.Parameter; } if (document == null) { IFileSystem fs = args.Host.FileSystems.Docuemnt; if (fs != null) { if (args.ShowUI) { // 浏览文件 fileName = fs.BrowseOpen(args.Host.Services, fileName); } if (string.IsNullOrEmpty(fileName)) { return; } VFileInfo info = fs.GetFileInfo(args.Host.Services, fileName); if (info.Exists == false) { // 文件不存在 return; } //打开文件 if (args.Host.Debuger != null) { args.Host.Debuger.DebugLoadingFile(fileName); } System.IO.Stream stream = fs.Open(args.Host.Services, fileName); if (stream != null) { FileFormat format = WriterUtils.ParseFileFormat(info.Format); using (stream) { // 读取文件,加载文档对象 document = new DomDocument(); document.Options = args.Document.Options; document.ServerObject = args.Document.ServerObject; document.Load(stream, format); if (args.Host.Debuger != null) { args.Host.Debuger.DebugLoadFileComplete((int)stream.Length); } } } } } if (document != null && document.Body != null && document.Body.Elements.Count > 0) { // 导入文档内容 DomElementList list = document.Body.Elements; args.Document.ImportElements(list); args.DocumentControler.InsertElements(list); args.Result = list; } } }