public WriteDocType ( string name, string pubid, string sysid, string subset ) : void | ||
name | string | |
pubid | string | |
sysid | string | |
subset | string | |
리턴 | void |
public static void SaveAsXml(IEnumerable<Chapter> chapters, string path) { var writer = new XmlTextWriter(path, Encoding.GetEncoding("ISO-8859-1")); writer.Formatting = Formatting.Indented; writer.WriteStartDocument(); writer.WriteDocType("Chapters", null, "matroskachapters.dtd", null); writer.WriteStartElement("Chapters"); writer.WriteStartElement("EditionEntry"); foreach (var chapter in chapters.Where(chapter => chapter.Keep)) { writer.WriteStartElement("ChapterAtom"); writer.WriteStartElement("ChapterTimeStart"); writer.WriteString(chapter.StartTimeXmlFormat); // 00:00:00.000 writer.WriteEndElement(); writer.WriteStartElement("ChapterDisplay"); writer.WriteStartElement("ChapterString"); writer.WriteString(chapter.Title); // Chapter 1 writer.WriteEndElement(); if (chapter.Language != null && chapter.Language != Language.Undetermined) { writer.WriteStartElement("ChapterLanguage"); writer.WriteString(chapter.Language.ISO_639_2); // eng writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteEndDocument(); writer.Close(); }
/// <summary> /// Export a MacGui style plist preset. /// </summary> /// <param name="path"> /// The path. /// </param> /// <param name="preset"> /// The preset. /// </param> public static void Export(string path, Preset preset) { EncodeTask parsed = QueryParserUtility.Parse(preset.Query); XmlTextWriter xmlWriter = new XmlTextWriter(path, Encoding.UTF8) { Formatting = Formatting.Indented }; // Header xmlWriter.WriteStartDocument(); xmlWriter.WriteDocType("plist", "-//Apple//DTD PLIST 1.0//EN", @"http://www.apple.com/DTDs/PropertyList-1.0.dtd", null); xmlWriter.WriteStartElement("plist"); xmlWriter.WriteStartElement("array"); // Add New Preset Here. Can write multiple presets here if required in future. WritePreset(xmlWriter, parsed, preset); // Footer xmlWriter.WriteEndElement(); xmlWriter.WriteEndElement(); xmlWriter.WriteEndDocument(); // Closeout xmlWriter.Close(); }
protected GXLExport(XmlTextWriter writer) { xmlwriter = writer; xmlwriter.Formatting = Formatting.Indented; xmlwriter.Indentation = 1; xmlwriter.WriteStartDocument(); xmlwriter.WriteDocType("gxl", null, "http://www.gupro.de/GXL/gxl-1.0.dtd", null); }
public void SaveXml(string filename) { const string lng = "eng"; var i = 0; var writer = new XmlTextWriter(filename, Encoding.GetEncoding("ISO-8859-1")); writer.Formatting = Formatting.Indented; writer.WriteStartDocument(); writer.WriteDocType("Chapters", null, "matroskachapters.dtd", null); writer.WriteStartElement("Chapters"); writer.WriteStartElement("EditionEntry"); foreach (var c in _chapters) { i++; var istr = i.ToString("00"); writer.WriteStartElement("ChapterAtom"); writer.WriteStartElement("ChapterTimeStart"); writer.WriteString(c.ToString()); writer.WriteEndElement(); writer.WriteStartElement("ChapterDisplay"); writer.WriteStartElement("ChapterString"); writer.WriteString("Chapter " + istr); writer.WriteEndElement(); writer.WriteStartElement("ChapterLanguage"); writer.WriteString(lng); writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteEndDocument(); writer.Close(); }
/// <summary> /// Export a MacGui style plist preset. /// </summary> /// <param name="path"> /// The path. /// </param> /// <param name="preset"> /// The preset. /// </param> /// <param name="build"> /// The build.PictureModulusPictureModulus /// </param> public static void Export(string path, Preset preset, string build) { if (string.IsNullOrEmpty(path)) { return; } EncodeTask parsed = new EncodeTask(preset.Task); using (XmlTextWriter xmlWriter = new XmlTextWriter(path, Encoding.UTF8) { Formatting = Formatting.Indented }) { // Header xmlWriter.WriteStartDocument(); xmlWriter.WriteDocType( "plist", "-//Apple//DTD PLIST 1.0//EN", @"http://www.apple.com/DTDs/PropertyList-1.0.dtd", null); xmlWriter.WriteStartElement("plist"); xmlWriter.WriteStartElement("array"); // Add New Preset Here. Can write multiple presets here if required in future. WritePreset(xmlWriter, parsed, preset, build); // Footer xmlWriter.WriteEndElement(); xmlWriter.WriteEndElement(); xmlWriter.WriteEndDocument(); // Closeout xmlWriter.Close(); } }
void IEpgDataSink.Open() { _writer = new XmlTextWriter(_xmltvTempFile, Encoding.UTF8); _writer.Formatting = Formatting.Indented; //Write the <xml version="1.0"> element _writer.WriteStartDocument(); _writer.WriteDocType("tv", null, "xmltv.dtd", null); _writer.WriteStartElement("tv"); _writer.WriteAttributeString("generator-info-name", "WebEPG"); _currentChannelName = string.Empty; }
public X3DExporter(string path) { Metadata = new Dictionary<string, string>(); writer = new XmlTextWriter(path, Encoding.UTF8); writer.Formatting = Formatting.Indented; writer.WriteStartDocument(false); writer.WriteDocType("X3D", "ISO//Web3D//DTD X3D 3.0//EN", "http://www.web3d.org/specifications/x3d-3.1.dtd", null); writer.WriteStartElement("X3D"); writer.WriteAttributeString("profile", "Immersive"); writer.WriteAttributeString("version", "3.1"); writer.WriteAttributeString("xmlns:xsd", "http://www.w3.org/2001/XMLSchema-instance"); writer.WriteAttributeString("xsd:noNamespaceSchemaLocation", "http://www.web3d.org/specifications/x3d-3.1.xsd"); }
public static void Generate(YmlCatalog catalog, string outputFileName) { var serializer = new XmlSerializer(typeof(YmlCatalog), ""); File.Delete(outputFileName); using (Stream textWriter = File.OpenWrite(outputFileName)) { using (var writer = new XmlTextWriter(textWriter, null)) { var ns = new XmlSerializerNamespaces(); ns.Add("", ""); writer.Formatting = Formatting.Indented; writer.WriteStartDocument(); writer.WriteDocType("yml_catalog", null, "shops.dtd", null); serializer.Serialize(writer, catalog, ns); } } }
public string ConvertProject(string xsltPath, string projectName) { var xTrf = new System.Xml.Xsl.XslCompiledTransform(true); var xTrfArg = new System.Xml.Xsl.XsltArgumentList(); var xSet = new System.Xml.Xsl.XsltSettings(true, true); var wSet = new System.Xml.XmlWriterSettings(); var mstr = new System.Xml.XmlTextWriter(new System.IO.MemoryStream(), System.Text.Encoding.UTF8); //var mstr = new System.Xml.XmlTextWriter(xsltPath + "test.xml", System.Text.Encoding.UTF8); var doc = new System.Xml.XmlDocument(); wSet = xTrf.OutputSettings; xTrf.Load(CopyXSLTFile(xsltPath), xSet, new XmlUrlResolver()); xTrfArg.AddParam("ProjectName", "", projectName); mstr.WriteStartDocument(); mstr.WriteDocType("Article", "-//RiQuest Software//DTD JBArticle v1.0 20020724//EN", "../dtd/JBArticle/jbarticle.dtd", null); xTrf.Transform(_extractPath + "/desktop.xml", xTrfArg, mstr); mstr.BaseStream.Flush(); mstr.BaseStream.Seek(0, System.IO.SeekOrigin.Begin); return(new StreamReader(mstr.BaseStream).ReadToEnd()); }
public AdiumSmileConfig(string path, PackInfo pack) : base(pack, "Adium", path) { this.path = packRootPath + String.Format("{0}.AdiumEmoticonSet/", PackFullName); this.imagePath = this.path; Directory.CreateDirectory(this.path); plistWriter = new XmlTextWriter(this.path + "Emoticons.plist", Encoding.UTF8); plistWriter.Formatting = Formatting.Indented; plistWriter.WriteStartDocument(); plistWriter.WriteDocType("plist", "-//Apple Computer//DTD PLIST 1.0//EN", "http://www.apple.com/DTDs/PropertyList-1.0.dtd", null); plistWriter.WriteStartElement("plist"); plistWriter.WriteAttributeString("version", "1.0"); plistWriter.WriteStartElement("dict"); plistWriter.WriteElementString("key", "AdiumSetVersion"); plistWriter.WriteElementString("integer", "1"); plistWriter.WriteElementString("key", "Emoticons"); plistWriter.WriteStartElement("dict"); }
private void WriteDocTypeOut(XmlTextReader inFile, XmlTextWriter xmlOutput) { if (currentRT.ClassName == "") //There is no cuurrently instantiazed class xmlOutput.WriteDocType(inFile.Name, null, null, null); else { throw new Exception("DocType input isn't until after the root element"); } }
//************************************************************************* // Method: SaveProject // // Description: Saves project settings to an XML file. // // Parameters: // fileName - file to save project to. // useExistingFilename - if true, fileName param. is ignored and the existing // filename is used // // Return Value: none //************************************************************************* public void SaveProject(String fileName, bool useExistingFilename) { if (!useExistingFilename) SavedProjectFileName = fileName; InterceptedFunctionDB db = InterceptedFunctionDB.GetInstance("functions.xml"); RegistryHelper helper = RegistryHelper.getInstance(); string dtdName = helper.GetDTDFolder(); if (dtdName == null) dtdName = "projectfile.dtd"; else if (dtdName.EndsWith("\\")) dtdName = string.Concat(dtdName, "projectfile.dtd"); else dtdName = string.Concat(dtdName, "\\projectfile.dtd"); XmlTextWriter xwriter = new XmlTextWriter(SavedProjectFileName,System.Text.Encoding.UTF8); xwriter.Formatting = Formatting.Indented; xwriter.Indentation = 4; xwriter.WriteStartDocument(false); xwriter.WriteDocType ("Project", null, dtdName, null); xwriter.WriteStartElement ("Project"); foreach(ProcessMdiWindow window in mdiWindowList) { xwriter.WriteStartElement ("ApplicationUnderTest"); xwriter.WriteStartElement ("AppInfo"); xwriter.WriteAttributeString ("ApplicationPathAndName", window.ProcessFile); if (window.UseProcessFile) xwriter.WriteAttributeString ("InjectMode", "LAUNCH"); else xwriter.WriteAttributeString ("InjectMode", "ATTACH"); xwriter.WriteAttributeString ("StartPaused", window.AppPaused.ToString()); xwriter.WriteFullEndElement (); //End for AppInfo xwriter.WriteStartElement ("FilteredFunctions"); foreach (string fName in window.FilteredOutFunctions) { InterceptedFunction function = db.GetFunctionByName(fName); if (function != null) { xwriter.WriteStartElement ("FilteredFunction"); xwriter.WriteAttributeString ("FunctionName", function.Name); xwriter.WriteFullEndElement(); } } xwriter.WriteFullEndElement(); //end for FilteredFunctions xwriter.WriteStartElement ("Faults"); xwriter.WriteStartElement ("DiskFaults"); EnumerateCheckAndSaveFaults ("Disk", ref xwriter, window); xwriter.WriteFullEndElement(); xwriter.WriteStartElement ("MemoryFaults"); EnumerateCheckAndSaveFaults ("Memory", ref xwriter, window); xwriter.WriteFullEndElement(); xwriter.WriteStartElement ("NetworkFaults"); EnumerateCheckAndSaveFaults ("Network", ref xwriter, window); xwriter.WriteFullEndElement(); xwriter.WriteFullEndElement(); //End for "Faults" xwriter.WriteStartElement ("Limits"); xwriter.WriteStartElement ("DiskSpaceLimit"); xwriter.WriteAttributeString ("LimitActivated", window.LimitDiskUsage.ToString()); xwriter.WriteAttributeString ("Limit", window.MaxDiskUsage.ToString()); xwriter.WriteAttributeString ("LimitUnit", window.MaxDiskUsageUnit); xwriter.WriteFullEndElement(); xwriter.WriteStartElement ("MemorySpaceLimit"); xwriter.WriteAttributeString ("LimitActivated", window.LimitMemoryUsage.ToString()); xwriter.WriteAttributeString ("Limit", window.MaxMemoryUsage.ToString()); xwriter.WriteAttributeString ("LimitUnit", window.MaxMemoryUsageUnit); xwriter.WriteFullEndElement(); xwriter.WriteStartElement ("NetworkThrottle"); xwriter.WriteAttributeString ("ThrottleActivated", window.LimitNetworkSpeed.ToString()); xwriter.WriteAttributeString ("ThrottlePercent", window.MaxNetworkSpeed.ToString()); xwriter.WriteFullEndElement(); xwriter.WriteFullEndElement(); //End for "Limits" xwriter.WriteStartElement ("ScheduledTests"); foreach (ListViewItem item in window.GetScheduledTests()) { InterceptedFunction f = InterceptedFunctionDB.GetInstance("functions.xml").GetFunctionByName(item.SubItems[1].Text); if (f != null) { xwriter.WriteStartElement ("ScheduledTest"); xwriter.WriteAttributeString("TestID",item.SubItems[0].Text); xwriter.WriteAttributeString("FunctionName", f.Name); xwriter.WriteAttributeString("Category", f.Category); xwriter.WriteAttributeString("ErrorCode", item.SubItems[2].Text); xwriter.WriteAttributeString("ReturnValue", item.SubItems[3].Text); xwriter.WriteAttributeString("Parameters", item.SubItems[4].Text); xwriter.WriteFullEndElement(); } } xwriter.WriteFullEndElement(); //End for "ScheduledTests" xwriter.WriteFullEndElement(); //end for ApplicationUnderTest } xwriter.WriteFullEndElement(); //End for "Project" xwriter.WriteEndDocument (); xwriter.Flush(); xwriter.Close(); }
private bool buildMod(string dir) { // If we don't have a working directory, we're screwed. if (string.IsNullOrEmpty(workingDirectory)) return false; // Create a Package and Source directory if they do not exist. if (!Directory.Exists(workingDirectory + "/Package")) Directory.CreateDirectory(workingDirectory + "/Package"); if (!Directory.Exists(workingDirectory + "/Source")) Directory.CreateDirectory(workingDirectory + "/Source"); // Check if something is empty. if (String.IsNullOrEmpty(modName.Text) || String.IsNullOrEmpty(modVersion.Text) || String.IsNullOrEmpty(modType.Text) || String.IsNullOrEmpty(modID.Text) || String.IsNullOrEmpty(modCompatibility.Text)) { // Yes it is, warn the user and reset to the main tab. modSettings.SelectedTab = modDetailsTab; // Also mark the required fields in a nice red colour. It goes away once something's typed. First up is name. if (String.IsNullOrEmpty(modName.Text)) modName.BackColor = Color.Red; // Version. if (String.IsNullOrEmpty(modVersion.Text)) modVersion.BackColor = Color.Red; // ID, when it is not set to automatically generate stuff. if (String.IsNullOrEmpty(modID.Text) && !genPkgID.Checked) modID.BackColor = Color.Red; // Type. if (String.IsNullOrEmpty(modType.Text)) modType.BackColor = Color.Red; // Compatibility. if (String.IsNullOrEmpty(modCompatibility.Text)) modCompatibility.BackColor = Color.Red; return false; } if (modID.Text.Length > 32) { MessageBox.Show("The mod ID is too long. Please shorten it to (less than) 32 characters. Build aborted.", "Build", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } // Grab the amount of instructions. string csql = "SELECT count(id) FROM instructions"; SQLiteCommand ccommand = new SQLiteCommand(csql, conn); SQLiteDataReader creader = ccommand.ExecuteReader(); creader.Read(); int numinst = Convert.ToInt32(creader[0]); // Lets build the package_info.xml. #region Build package-info.xml using (FileStream fileStream = new FileStream(workingDirectory + "/Package/package-info.xml", FileMode.Create)) using (StreamWriter sw = new StreamWriter(fileStream)) using (XmlTextWriter writer = new XmlTextWriter(sw)) { // Some settings before we start. writer.Formatting = Formatting.Indented; writer.Indentation = 4; // Start the document. writer.WriteStartDocument(); // Doctype (the writer.WriteDocType stuff was confusing me) writer.WriteDocType("package-info", null, "http://www.simplemachines.org/xml/package-info", null); //writer.WriteRaw("<!DOCTYPE package-info SYSTEM \"http://www.simplemachines.org/xml/package-info\">"); // Some sort of generator copyright. if (includeModManLine.Checked == true) writer.WriteComment("Generated with Mod Manager (c) 2013 Yoshi2889"); // Write the package-info start element. writer.WriteStartElement("package-info", "http://www.simplemachines.org/xml/package-info"); writer.WriteAttributeString("xmlns", "smf", null, "http://www.simplemachines.org/"); // Write the ID. writer.WriteElementString("id", modID.Text); // Name. writer.WriteElementString("name", modName.Text); // Version. writer.WriteElementString("version", modVersion.Text); // Determine the type. Dictionary<string, string> types = new Dictionary<string, string>(); types.Add("Modification", "modification"); types.Add("Avatar pack", "avatar"); string type = types[modType.Text]; // And write it. writer.WriteElementString("type", type); // Installation instructions. writer.WriteStartElement("install"); writer.WriteAttributeString("for", modCompatibility.Text); // Readme. if (!string.IsNullOrEmpty(modReadme.Text)) { writer.WriteStartElement("readme"); writer.WriteAttributeString("parsebbc", "true"); writer.WriteString("readme.txt"); writer.WriteEndElement(); } // And installation XML. if (!ignoreInstructions.Checked && numinst != 0) writer.WriteElementString("modification", "install.xml"); // If we have a custom install code text thing entered, now's the time to add it. if (!string.IsNullOrEmpty(customCodeInstall.Text)) writer.WriteElementString("code", "install.php"); if (!string.IsNullOrEmpty(installDatabaseCode.Text)) writer.WriteElementString("database", "installDatabase.php"); // Now for the extraction of files and/or dirs. if (hasConn) { string sql = "SELECT id, file_name, destination FROM files"; SQLiteCommand command = new SQLiteCommand(sql, conn); SQLiteDataReader reader = command.ExecuteReader(); while (reader.Read()) { if (!File.Exists(workingDirectory + "\\Source\\" + reader["file_name"].ToString()) && Directory.Exists(workingDirectory + "\\Source\\" + reader["file_name"].ToString())) writer.WriteStartElement("require-dir"); else writer.WriteStartElement("require-file"); writer.WriteAttributeString("name", "files/" + reader["file_name"].ToString().Replace("\\", "/")); writer.WriteAttributeString("destination", reader["destination"].ToString().Replace("\\", "/")); writer.WriteEndElement(); } } // End the element and document. writer.WriteEndElement(); // Uninstallation instructions! writer.WriteStartElement("uninstall"); writer.WriteAttributeString("for", modCompatibility.Text); if (!ignoreInstructions.Checked && numinst != 0) { writer.WriteStartElement("modification"); writer.WriteAttributeString("reverse", "true"); writer.WriteString("install.xml"); writer.WriteEndElement(); } // Got custom uninstall code? Enter it. if (!string.IsNullOrEmpty(customCodeUninstall.Text)) writer.WriteElementString("code", "uninstall.php"); if (!string.IsNullOrEmpty(uninstallDatabaseCode.Text)) writer.WriteElementString("database", "uninstallDatabase.php"); if (hasConn) { // Now for the deletion of files and dirs. string sql2 = "SELECT id, file_name, type FROM files_delete"; SQLiteCommand command2 = new SQLiteCommand(sql2, conn); SQLiteDataReader reader2 = command2.ExecuteReader(); string intype = ""; while (reader2.Read()) { switch (reader2["type"].ToString()) { case "dir": intype = "dir"; break; default: intype = "file"; break; } writer.WriteStartElement("remove-" + intype); writer.WriteAttributeString("name", reader2["file_name"].ToString()); writer.WriteEndElement(); } } writer.WriteEndElement(); // Last but not least the end of the document. writer.WriteEndDocument(); // Flush and end! writer.Flush(); writer.Close(); } #endregion // Some settings before we start writing install.xml. #region Build install.xml if (!ignoreInstructions.Checked) { if (numinst != 0) { using (FileStream fileStream = new FileStream(workingDirectory + "/Package/install.xml", FileMode.Create)) using (StreamWriter sw = new StreamWriter(fileStream)) using (XmlTextWriter writer = new XmlTextWriter(sw)) { // Some settings before we start. writer.Formatting = Formatting.Indented; writer.Indentation = 4; // Start the document. writer.WriteStartDocument(); // Doctype (the writer.WriteDocType stuff was confusing me) writer.WriteDocType("modification", null, "http://www.simplemachines.org/xml/modification", null); // Some sort of generator copyright. if (includeModManLine.Checked == true) writer.WriteComment("Generated with Mod Manager (c) 2013 Yoshi2889"); // Write the package-info start element. writer.WriteStartElement("modification", "http://www.simplemachines.org/xml/modification"); writer.WriteAttributeString("xmlns", "smf", null, "http://www.simplemachines.org/"); // Write the ID. writer.WriteElementString("id", modID.Text); // Version. writer.WriteElementString("version", modVersion.Text); // Grab the data. if (hasConn) { string sql = "SELECT id, before, after, type, file, optional FROM instructions ORDER BY file"; SQLiteCommand command = new SQLiteCommand(sql, conn); SQLiteDataReader reader = command.ExecuteReader(); string lastfile = ""; string file = ""; bool hasstarted = false; while (reader.Read()) { if (string.IsNullOrEmpty(lastfile)) lastfile = file; file = Convert.ToString(reader["file"]); if (lastfile != file && Properties.Settings.Default.groupInstructions) { if (hasstarted) writer.WriteEndElement(); writer.WriteStartElement("file"); writer.WriteAttributeString("name", file); } else if (!Properties.Settings.Default.groupInstructions) { writer.WriteStartElement("file"); writer.WriteAttributeString("name", file); } writer.WriteStartElement("operation"); if (Convert.ToInt32(reader["optional"]) == 1) writer.WriteAttributeString("error", "skip"); writer.WriteStartElement("search"); string fintype = ""; switch (Convert.ToString(reader["type"])) { case "add_before": fintype = "after"; break; case "add_after": fintype = "before"; break; case "replace": fintype = "replace"; break; case "end": fintype = "end"; break; } writer.WriteAttributeString("position", fintype); if (fintype != "end") { writer.WriteRaw("<![CDATA[" + Convert.ToString(reader["before"]).Replace("]]>", "]]]]><![CDATA[>") + "]]>"); } // search end writer.WriteEndElement(); writer.WriteStartElement("add"); writer.WriteRaw("<![CDATA[" + Convert.ToString(reader["after"]).Replace("]]>", "]]]]><![CDATA[>") + "]]>"); writer.WriteEndElement(); // operation end writer.WriteEndElement(); if (!Properties.Settings.Default.groupInstructions) writer.WriteEndElement(); lastfile = file; hasstarted = true; } } writer.WriteEndElement(); writer.WriteEndDocument(); writer.Flush(); writer.Close(); } } else { if (File.Exists(workingDirectory + "/Package/install.xml")) File.Delete(workingDirectory + "/Package/install.xml"); } } // If we did select to ignore the instructions part, delete the install.xml file. The data is stored in the database anyway. else if (ignoreInstructions.Checked && File.Exists(workingDirectory + "/Package/install.xml")) File.Delete(workingDirectory + "/Package/install.xml"); #endregion #region Writing files // File -> string to write Dictionary<string, string> filesToHandle = new Dictionary<string, string>(); // The readme. filesToHandle.Add("readme.txt", modReadme.Text); // Custom installation file. filesToHandle.Add("install.php", customCodeInstall.Text); // Custom uninstallation file. filesToHandle.Add("uninstall.php", customCodeUninstall.Text); // Custom database installation file. filesToHandle.Add("installDatabase.php", installDatabaseCode.Text); // Custom database deinstallation file. filesToHandle.Add("uninstallDatabase.php", uninstallDatabaseCode.Text); // For every file, perform a few operations. foreach (var pair in filesToHandle) { // If we have a valid check, write the file. if (!string.IsNullOrEmpty(pair.Value)) File.WriteAllText(workingDirectory + "/Package/" + pair.Key, pair.Value); // Else if we left out data for this file, remove it to save possible space and empty files in the package else if (string.IsNullOrEmpty(pair.Value) && File.Exists(workingDirectory + "/Package/" + pair.Key)) File.Delete(workingDirectory + "/Package/" + pair.Key); } #endregion // Do we have a database? if (!hasConn) generateSQL(workingDirectory); // Return true so we know. return true; }
// Constructor public Hxc(string name, string title, string langId, string version, string copyright, string outputDirectory, Encoding encoding) { if (!Directory.Exists(outputDirectory)) { try { Directory.CreateDirectory(outputDirectory); } catch (Exception ex) { throw ex; } } try { System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(Path.Combine(outputDirectory, name + ".hxc"), null); writer.Formatting = Formatting.Indented; writer.WriteStartDocument(); writer.WriteDocType("HelpCollection", null, "MS-Help://Hx/Resources/HelpCollection.dtd", null); writer.WriteStartElement("HelpCollection"); writer.WriteAttributeString("DTDVersion", "1.0"); writer.WriteAttributeString("FileVersion", version); writer.WriteAttributeString("LangId", langId); writer.WriteAttributeString("Title", title); writer.WriteAttributeString("Copyright", copyright); writer.WriteStartElement("CompilerOptions"); writer.WriteAttributeString("OutputFile", string.Format("{0}{1}", name, ".HxS")); writer.WriteAttributeString("CreateFullTextIndex", "Yes"); writer.WriteAttributeString("CompileResult", "Hxs"); writer.WriteAttributeString("StopWordFile", "msdnFTSstop_Unicode.stp"); writer.WriteStartElement("IncludeFile"); writer.WriteAttributeString("File", string.Format("{0}{1}", name, ".HxF")); writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteStartElement("TOCDef"); writer.WriteAttributeString("File", string.Format("{0}{1}", name, ".HxT")); writer.WriteEndElement(); writer.WriteStartElement("KeywordIndexDef"); writer.WriteAttributeString("File", string.Format("{0}{1}", name, "K.HxK")); writer.WriteEndElement(); writer.WriteStartElement("KeywordIndexDef"); writer.WriteAttributeString("File", string.Format("{0}{1}", name, "F.HxK")); writer.WriteEndElement(); writer.WriteStartElement("KeywordIndexDef"); writer.WriteAttributeString("File", string.Format("{0}{1}", name, "N.HxK")); writer.WriteEndElement(); writer.WriteStartElement("KeywordIndexDef"); writer.WriteAttributeString("File", string.Format("{0}{1}", name, "A.HxK")); writer.WriteEndElement(); writer.WriteStartElement("KeywordIndexDef"); writer.WriteAttributeString("File", string.Format("{0}{1}", name, "S.HxK")); writer.WriteEndElement(); writer.WriteStartElement("KeywordIndexDef"); writer.WriteAttributeString("File", string.Format("{0}{1}", name, "B.HxK")); writer.WriteEndElement(); // <ItemMoniker Name="!DefaultTOC" ProgId="HxDs.HxHierarchy" InitData="AnyString" /> writer.WriteStartElement("ItemMoniker"); writer.WriteAttributeString("Name", "!DefaultTOC"); writer.WriteAttributeString("ProgId", "HxDs.HxHierarchy"); writer.WriteAttributeString("InitData", "AnyString"); writer.WriteEndElement(); // <ItemMoniker Name="!DefaultFullTextSearch" ProgId="HxDs.HxFullTextSearch" InitData="AnyString" /> writer.WriteStartElement("ItemMoniker"); writer.WriteAttributeString("Name", "!DefaultFullTextSearch"); writer.WriteAttributeString("ProgId", "HxDs.HxFullTextSearch"); writer.WriteAttributeString("InitData", "AnyString"); writer.WriteEndElement(); // <ItemMoniker Name="!DefaultAssociativeIndex" ProgId="HxDs.HxIndex" InitData="A" /> writer.WriteStartElement("ItemMoniker"); writer.WriteAttributeString("Name", "!DefaultAssociativeIndex"); writer.WriteAttributeString("ProgId", "HxDs.HxIndex"); writer.WriteAttributeString("InitData", "A"); writer.WriteEndElement(); // <ItemMoniker Name="!DefaultKeywordIndex" ProgId="HxDs.HxIndex" InitData="K" /> writer.WriteStartElement("ItemMoniker"); writer.WriteAttributeString("Name", "!DefaultKeywordIndex"); writer.WriteAttributeString("ProgId", "HxDs.HxIndex"); writer.WriteAttributeString("InitData", "K"); writer.WriteEndElement(); // <ItemMoniker Name="!DefaultContextWindowIndex" ProgId="HxDs.HxIndex" InitData="F" /> writer.WriteStartElement("ItemMoniker"); writer.WriteAttributeString("Name", "!DefaultContextWindowIndex"); writer.WriteAttributeString("ProgId", "HxDs.HxIndex"); writer.WriteAttributeString("InitData", "F"); writer.WriteEndElement(); // <ItemMoniker Name="!DefaultNamedUrlIndex" ProgId="HxDs.HxIndex" InitData="NamedUrl" /> writer.WriteStartElement("ItemMoniker"); writer.WriteAttributeString("Name", "!DefaultNamedUrlIndex"); writer.WriteAttributeString("ProgId", "HxDs.HxIndex"); writer.WriteAttributeString("InitData", "NamedUrl"); writer.WriteEndElement(); // <ItemMoniker Name="!DefaultSearchWindowIndex" ProgId="HxDs.HxIndex" InitData="S" /> writer.WriteStartElement("ItemMoniker"); writer.WriteAttributeString("Name", "!DefaultSearchWindowIndex"); writer.WriteAttributeString("ProgId", "HxDs.HxIndex"); writer.WriteAttributeString("InitData", "S"); writer.WriteEndElement(); // <ItemMoniker Name="!DefaultDynamicLinkIndex" ProgId="HxDs.HxIndex" InitData="B" /> writer.WriteStartElement("ItemMoniker"); writer.WriteAttributeString("Name", "!DefaultDynamicLinkIndex"); writer.WriteAttributeString("ProgId", "HxDs.HxIndex"); writer.WriteAttributeString("InitData", "B"); writer.WriteEndElement(); writer.WriteEndElement(); writer.Flush(); writer.Close(); writer = null; } catch (Exception ex) { throw ex; } }
public string ConvertProject(string xsltPath, string projectName) { var xTrf = new System.Xml.Xsl.XslCompiledTransform(true); var xTrfArg = new System.Xml.Xsl.XsltArgumentList(); var xSet = new System.Xml.Xsl.XsltSettings(true, true); var wSet = new System.Xml.XmlWriterSettings(); var mstr = new System.Xml.XmlTextWriter(new System.IO.MemoryStream(), System.Text.Encoding.UTF8); //var mstr = new System.Xml.XmlTextWriter(xsltPath + "test.xml", System.Text.Encoding.UTF8); var doc = new System.Xml.XmlDocument(); wSet = xTrf.OutputSettings; xTrf.Load(CopyXSLTFile(xsltPath), xSet, new XmlUrlResolver()); xTrfArg.AddParam("ProjectName", "", projectName); mstr.WriteStartDocument(); mstr.WriteDocType("Article", "-//RiQuest Software//DTD JBArticle v1.0 20020724//EN", "../dtd/JBArticle/jbarticle.dtd", null); xTrf.Transform(_extractPath + "/desktop.xml", xTrfArg, mstr); mstr.BaseStream.Flush(); mstr.BaseStream.Seek(0, System.IO.SeekOrigin.Begin); return new StreamReader(mstr.BaseStream).ReadToEnd(); }
///************************************************************************* /// Method: saveFunctionXmlDocument /// Description: recreating functions.xml document /// /// Parameters: /// functionXMLNavigator : /// /// fileNameToSaveAs : filename /// /// Return Value: None ///************************************************************************* public void saveFunctionXmlDocument(FunctionXMLNavigator functionXMLNavigator, string fileNameToSaveAs,string fileEncoding,bool isValidationRequired) { XmlTextWriter saveFunctionXml; switch(fileEncoding.ToUpper()) { case "UTF-8": case "": { saveFunctionXml = new XmlTextWriter(fileNameToSaveAs,System.Text.UTF8Encoding.UTF8); saveFunctionXml.Formatting = Formatting.Indented; saveFunctionXml.WriteRaw( "<?xml version= \"1.0\"?>" ); break; } case "UTF-7": { saveFunctionXml = new XmlTextWriter(fileNameToSaveAs,System.Text.UTF7Encoding.UTF7); saveFunctionXml.Formatting = Formatting.Indented; saveFunctionXml.WriteRaw( "<?xml version= \"1.0\" encoding=\"UTF-7\"?>" ); break; } case "ASCII": { saveFunctionXml = new XmlTextWriter(fileNameToSaveAs,System.Text.ASCIIEncoding.ASCII); saveFunctionXml.Formatting = Formatting.Indented; saveFunctionXml.WriteRaw( "<?xml version= \"1.0\" encoding=\"ASCII\"?>" ); break; } case "Unicode": { saveFunctionXml = new XmlTextWriter(fileNameToSaveAs,System.Text.UnicodeEncoding.Unicode); saveFunctionXml.Formatting = Formatting.Indented; saveFunctionXml.WriteRaw( "<?xml version= \"1.0\" encoding=\"Unicode\"?>" ); break; } default: { saveFunctionXml = new XmlTextWriter(fileNameToSaveAs,null); saveFunctionXml.Formatting = Formatting.Indented; saveFunctionXml.WriteRaw( "<?xml version= \"1.0\"?>" ); break; } } if(isValidationRequired) { saveFunctionXml.WriteDocType("Functions",null,"functions.dtd",""); } saveFunctionXml.WriteStartElement("Functions"); foreach(string FunctionNameAsKey in FunctionTableByName.Keys) { Function FunctionToSave = functionXMLNavigator.GetFunctionByName(FunctionNameAsKey); ///Element = Function saveFunctionXml.WriteStartElement("Function"); //Element = FunctionName saveFunctionXml.WriteStartElement("FunctionName"); saveFunctionXml.WriteString(FunctionToSave.FunctionName.ToString()); saveFunctionXml.WriteFullEndElement(); //Element = OriginalDll saveFunctionXml.WriteStartElement("OriginalDll"); saveFunctionXml.WriteString(FunctionToSave.OriginalDll.ToString()); saveFunctionXml.WriteFullEndElement(); //Element = InterceptedDll saveFunctionXml.WriteStartElement("InterceptedDll"); saveFunctionXml.WriteString(FunctionToSave.InterceptedDll.ToString()); saveFunctionXml.WriteFullEndElement(); //Element = ReplacementFunctionName saveFunctionXml.WriteStartElement("ReplacementFunctionName"); saveFunctionXml.WriteString(FunctionToSave.ReplacementFunctionName.ToString()); saveFunctionXml.WriteFullEndElement(); //Element = ReturnType saveFunctionXml.WriteStartElement("ReturnType"); saveFunctionXml.WriteString(FunctionToSave.ReturnType.ToString()); saveFunctionXml.WriteFullEndElement(); //Element = Modifier for(int indexModifier =0; indexModifier < FunctionToSave.Modifiers.Count;indexModifier ++) { saveFunctionXml.WriteStartElement("TypeModifier"); saveFunctionXml.WriteString(FunctionToSave.Modifiers[indexModifier].ToString()); saveFunctionXml.WriteFullEndElement(); } //Element = CallingConventionModifier for(int indexCallingConventionModifier =0; indexCallingConventionModifier < FunctionToSave.CallingConventionModifier.Count;indexCallingConventionModifier ++) { saveFunctionXml.WriteStartElement("CallingConventionModifier"); saveFunctionXml.WriteString(FunctionToSave.CallingConventionModifier[indexCallingConventionModifier].ToString()); saveFunctionXml.WriteFullEndElement(); } //Element = Category saveFunctionXml.WriteStartElement("Category"); saveFunctionXml.WriteString(FunctionToSave.Category.ToString()); saveFunctionXml.WriteFullEndElement(); ///Element = ReturnValue foreach(ReturnValue returnValue in FunctionToSave.ReturnValue) { ///Element = ReturnValue saveFunctionXml.WriteStartElement("ReturnValue"); ///Attribute = Type if(returnValue.Type != null) { saveFunctionXml.WriteAttributeString("Type",returnValue.Type.ToString()); } ///Attribute = ValueOperator if(returnValue.ValueOperator != null) { saveFunctionXml.WriteAttributeString("ValueOperator",returnValue.ValueOperator.ToString()); } saveFunctionXml.WriteString(returnValue.NodeValue.ToString()); saveFunctionXml.WriteFullEndElement(); } ///Element = Exception for(int indexException =0; indexException < FunctionToSave.Exception.Count;indexException ++) { saveFunctionXml.WriteStartElement("Exception"); saveFunctionXml.WriteString(FunctionToSave.Exception[indexException].ToString()); saveFunctionXml.WriteFullEndElement(); } /// Element = HelpLink saveFunctionXml.WriteStartElement("HelpLink"); saveFunctionXml.WriteString(FunctionToSave.HelpLink.ToString()); saveFunctionXml.WriteFullEndElement(); /// Element = Param foreach(Parameter param in FunctionToSave.Parameter) { ///Element = Param saveFunctionXml.WriteStartElement("Param"); ///Attribute = Index if(param.Index != -1) { saveFunctionXml.WriteAttributeString("Index",param.Index.ToString()); } ///Attribute = Type if(param.Type != null) { saveFunctionXml.WriteAttributeString("Type",param.Type.ToString()); } ///Attribute = CompareAs if(param.CompareAs != null) { saveFunctionXml.WriteAttributeString("CompareAs",param.CompareAs.ToString()); } ///Attribute = Access if(param.Access != null) { saveFunctionXml.WriteAttributeString("Access",param.Access.ToString()); } ///Attribute = PointsToResource if(param.PointsToResource != null) { saveFunctionXml.WriteAttributeString("PointsToResource",param.PointsToResource.ToString()); } ///Attribute = ConcatWith if(param.ConcatWith != null) { saveFunctionXml.WriteAttributeString("ConcatWith",param.ConcatWith.ToString()); } ///Attribute = MapTo if(param.MapTo != null) { saveFunctionXml.WriteAttributeString("MapTo",param.MapTo.ToString()); } saveFunctionXml.WriteString(param.Name.ToString()); saveFunctionXml.WriteFullEndElement(); } ///Element = ErrorCode foreach(ErrorCode errorCode in FunctionToSave.ErrorCode) { ///Element = ErrorCode saveFunctionXml.WriteStartElement("ErrorCode"); ///Attribute = IdentifyBy if(errorCode.IdentifiedBy != null) { saveFunctionXml.WriteAttributeString("IdentifyBy",errorCode.IdentifiedBy.ToString()); } ///Attribute = Type if(errorCode.Type != null) { saveFunctionXml.WriteAttributeString("Type",errorCode.Type.ToString()); } saveFunctionXml.WriteString(errorCode.NodeValue.ToString()); saveFunctionXml.WriteFullEndElement(); } saveFunctionXml.WriteFullEndElement(); } saveFunctionXml.WriteFullEndElement(); //closing xmlwriter. saveFunctionXml.Close(); }
/// <summary> /// Idea here is to re-create the XmlTextReader Node and this accounts for 50% of the code. /// Original code borrowed from http://www.sdltridionworld.com/community/2011_extensions/parentchangenotifier.aspx /// Thanks for the work from Serguei Martchenko - would not be possible without his example! /// </summary> /// <param name="xReader"></param> /// <param name="context"></param> /// <returns></returns> private XmlTextReader PreprocessListItems(XmlTextReader xReader, PipelineContext context) { TextWriter sWriter = new StringWriter(); XmlTextWriter xWriter = new XmlTextWriter(sWriter); string attrName = "metadataFieldValue"; string attrValue = ""; // set this to 'fieldValue', for example, to debug and prove it is working xReader.MoveToContent(); using(var tdse = new TDSEWrapper()) { while (!xReader.EOF) { switch (xReader.NodeType) { case XmlNodeType.Element: xWriter.WriteStartElement(xReader.Prefix, xReader.LocalName, xReader.NamespaceURI); // add all attributes back -- always START with this to NOT break the GUI xWriter.WriteAttributes(xReader, false); try { // add my custom attribute if (IsValidItem(xReader)) { string id = xReader.GetAttribute("ID"); // URI TcmUri uri = new TcmUri(id); if (uri.ItemType == ItemType.Component) { // Get Metadata Value // 0 seconds with no processing // 12 seconds for 250 Components with TOM API, Component.MetadataFields... // 12 seconds for 250 Components with Core Service // 2 seconds for 250 Components with TOM API and GetXML (FASTEST!) // Core Service //attrValue = GetMetadataValue(fieldName, id); // TDSE...Fastest with GetXML Component comp = tdse.TDSE.GetObject(id, Tridion.ContentManager.Interop.TDSDefines.EnumOpenMode.OpenModeView) as Component; attrValue = GetMetadataValue(comp, "article_number"); } // add new metadata field attribute xWriter.WriteAttributeString(attrName, attrValue); xReader.MoveToElement(); } } catch (Exception ex) { Trace.TraceError("EXCEPTION " + ex.Message + ex.ToString() + ex.StackTrace); } if (xReader.IsEmptyElement) { xWriter.WriteEndElement(); } break; case XmlNodeType.EndElement: xWriter.WriteEndElement(); break; case XmlNodeType.CDATA: // Copy CDATA node <![CDATA[]]> xWriter.WriteCData(xReader.Value); break; case XmlNodeType.Comment: // Copy comment node <!-- --> xWriter.WriteComment(xReader.Value); break; case XmlNodeType.DocumentType: // Copy XML documenttype xWriter.WriteDocType(xReader.Name, null, null, null); break; case XmlNodeType.EntityReference: xWriter.WriteEntityRef(xReader.Name); break; case XmlNodeType.ProcessingInstruction: xWriter.WriteProcessingInstruction(xReader.Name, xReader.Value); break; case XmlNodeType.SignificantWhitespace: xWriter.WriteWhitespace(xReader.Value); break; case XmlNodeType.Text: xWriter.WriteString(xReader.Value); break; case XmlNodeType.Whitespace: xWriter.WriteWhitespace(xReader.Value); break; } xReader.Read(); }; } xWriter.Flush(); xReader = new XmlTextReader(new StringReader(sWriter.ToString())); xReader.MoveToContent(); //-> Write XML of tcm:Item out... // This is where the attribute in the config file is matched. // Trace.Write(sWriter.ToString() + Environment.NewLine); return xReader; }
public string CreateChapterFile(ChapterDBAccess.ChapterSet chapterSet, string path, bool overwrite) { WriteLog("Creating chapterfile"); if (Path.GetExtension(path) != ".xml") { path += "\\chapters.xml"; } if (File.Exists(path)) { //If the there already exists a file with the same name as the specified, check if we should overwrite if (!overwrite) { //If we shouldn't overwrite, exit return null; } //Delete the existing file File.Delete(path); } var xwrite = new XmlTextWriter(path, Encoding.UTF8); xwrite.WriteStartDocument(); xwrite.Formatting = Formatting.Indented; xwrite.Indentation = 2; xwrite.WriteDocType("Tags", null, "matroskatags.dtd", null); xwrite.WriteStartElement("Chapters"); xwrite.WriteStartElement("EditionEntry"); foreach (ChapterDBAccess.Chapter chapter in chapterSet.Chapters) { xwrite.WriteStartElement("ChapterAtom"); xwrite.WriteElementString("ChapterTimeStart", string.Format("{0:00}:{1:00}:{2:00}.000000000", chapter.Time.Hours, chapter.Time.Minutes, chapter.Time.Seconds)); xwrite.WriteStartElement("ChapterDisplay"); xwrite.WriteElementString("ChapterString", chapter.Name); xwrite.WriteEndElement(); xwrite.WriteEndElement(); } xwrite.WriteEndElement(); xwrite.WriteEndElement(); xwrite.Close(); return path; }
public void WriteDocType () { // we have the following test matrix: // // | name | publicid | systemid | subset| // |------------------------------------| // | X | X | X | X | #01 // | X | E | X | X | #02 // | X | X | E | X | #03 // | X | X | X | E | #04 // | X | E | E | X | #05 // | X | X | E | E | #06 // | X | E | X | E | #07 // | X | E | E | E | #08 // | X | N | X | X | #09 // | X | X | N | X | #10 // | X | X | X | N | #11 // | X | N | N | X | #12 // | X | X | N | N | #13 // | X | N | X | N | #14 // | X | N | N | N | #15 // // Legend: // ------- // X = Has value // E = Zero-length string // N = Null xtw.WriteDocType ("test", "-//W3C//DTD XHTML 1.0 Strict//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd", "sub"); Assert.AreEqual ("<!DOCTYPE test PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'" + " 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'[sub]>", sw.ToString (), "#01"); sw.GetStringBuilder ().Length = 0; xtw = new XmlTextWriter (sw); xtw.WriteDocType ("test", string.Empty, "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd", "sub"); Assert.AreEqual ("<!DOCTYPE test PUBLIC \"\"" + " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"[sub]>", sw.ToString (), "#02"); sw.GetStringBuilder ().Length = 0; xtw = new XmlTextWriter (sw); xtw.WriteDocType ("test", "-//W3C//DTD XHTML 1.0 Strict//EN", string.Empty, "sub"); Assert.AreEqual ("<!DOCTYPE test PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"" + " \"\"[sub]>", sw.ToString (), "#03"); sw.GetStringBuilder ().Length = 0; xtw = new XmlTextWriter (sw); xtw.WriteDocType ("test", "-//W3C//DTD XHTML 1.0 Strict//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd", string.Empty); Assert.AreEqual ("<!DOCTYPE test PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"" + " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"[]>", sw.ToString (), "#04"); sw.GetStringBuilder ().Length = 0; xtw = new XmlTextWriter (sw); xtw.WriteDocType ("test", string.Empty, string.Empty, "sub"); Assert.AreEqual ("<!DOCTYPE test PUBLIC \"\" \"\"[sub]>", sw.ToString (), "#05"); sw.GetStringBuilder ().Length = 0; xtw = new XmlTextWriter (sw); xtw.WriteDocType ("test", "-//W3C//DTD XHTML 1.0 Strict//EN", string.Empty, string.Empty); Assert.AreEqual ("<!DOCTYPE test PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"" + " \"\"[]>", sw.ToString (), "#06"); sw.GetStringBuilder ().Length = 0; xtw = new XmlTextWriter (sw); xtw.WriteDocType ("test", string.Empty, "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd", string.Empty); Assert.AreEqual ("<!DOCTYPE test PUBLIC \"\"" + " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"[]>", sw.ToString (), "#07"); sw.GetStringBuilder ().Length = 0; xtw = new XmlTextWriter (sw); xtw.WriteDocType ("test", string.Empty, string.Empty, string.Empty); Assert.AreEqual ("<!DOCTYPE test PUBLIC \"\" \"\"[]>", sw.ToString (), "#08"); sw.GetStringBuilder ().Length = 0; xtw = new XmlTextWriter (sw); xtw.WriteDocType ("test", (string) null, "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd", "sub"); Assert.AreEqual ("<!DOCTYPE test SYSTEM" + " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"[sub]>", sw.ToString (), "#09"); sw.GetStringBuilder ().Length = 0; xtw = new XmlTextWriter (sw); xtw.WriteDocType ("test", "-//W3C//DTD XHTML 1.0 Strict//EN", (string) null, "sub"); Assert.AreEqual ("<!DOCTYPE test PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"" + " \"\"[sub]>", sw.ToString (), "#10"); sw.GetStringBuilder ().Length = 0; xtw = new XmlTextWriter (sw); xtw.WriteDocType ("test", "-//W3C//DTD XHTML 1.0 Strict//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd", (string) null); Assert.AreEqual ("<!DOCTYPE test PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"" + " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">", sw.ToString (), "#11"); sw.GetStringBuilder ().Length = 0; xtw = new XmlTextWriter (sw); xtw.WriteDocType ("test", (string) null, (string) null, "sub"); Assert.AreEqual ("<!DOCTYPE test[sub]>", sw.ToString (), "#12"); sw.GetStringBuilder ().Length = 0; xtw = new XmlTextWriter (sw); xtw.WriteDocType ("test", "-//W3C//DTD XHTML 1.0 Strict//EN", (string) null, (string) null); Assert.AreEqual ("<!DOCTYPE test PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"" + " \"\">", sw.ToString (), "#13"); sw.GetStringBuilder ().Length = 0; xtw = new XmlTextWriter (sw); xtw.WriteDocType ("test", (string) null, "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd", (string) null); Assert.AreEqual ("<!DOCTYPE test SYSTEM" + " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">", sw.ToString (), "#14"); sw.GetStringBuilder ().Length = 0; xtw = new XmlTextWriter (sw); xtw.WriteDocType ("test", (string) null, (string) null, (string) null); Assert.AreEqual ("<!DOCTYPE test>", sw.ToString (), "#15"); }
/// <summary> /// Save the current map to an XML-File /// </summary> /// <param name="fileName">The filename to be used (XML-extension automatically appended)</param> public void Save(string fileName) { fileName = fileName.ToLower().Trim(); if (!fileName.EndsWith(".xml")) { fileName += ".xml"; } XmlTextWriter writer = new XmlTextWriter(fileName, null); System.Diagnostics.Debug.WriteLine("Save to " + fileName); writer.WriteStartDocument(); writer.WriteDocType("crawlMap", null, null, null); writer.WriteComment("Verbose Map file for Crawler Prototype"); writer.WriteStartElement("map"); writer.WriteAttributeString("width", _width.ToString()); writer.WriteAttributeString("height", _height.ToString()); if (_rows != null) { foreach (Row row in _rows) { row.Save(writer); }; } writer.WriteEndElement(); writer.WriteEndDocument(); writer.Close(); }
//************************************************************************* // Method: saveFaultXmlDocument // Description: recreating fault.xml document // // Parameters: // faultXMLNavigator // // Return Value: None // // Output: "Faults.xml" file will be created in this application directory //************************************************************************* public void saveFaultXmlDocument(FaultXMLNavigator faultXMLNavigator, string fileNameToSaveAs,string fileEncoding,bool isValidationRequired ) { XmlTextWriter saveFaultXml = null ; Console.WriteLine(fileNameToSaveAs); switch(fileEncoding.ToUpper()) { case "UTF-8": case "": { Console.WriteLine(fileNameToSaveAs); saveFaultXml = new XmlTextWriter(fileNameToSaveAs,System.Text.UTF8Encoding.UTF8); saveFaultXml.Formatting = Formatting.Indented; saveFaultXml.WriteRaw( "<?xml version= \"1.0\"?>" ); break; } case "UTF-7": { Console.WriteLine(fileNameToSaveAs); saveFaultXml = new XmlTextWriter(fileNameToSaveAs,System.Text.UTF7Encoding.UTF7); saveFaultXml.Formatting = Formatting.Indented; saveFaultXml.WriteRaw( "<?xml version= \"1.0\" encoding=\"UTF-7\"?>" ); break; } case "ASCII": { Console.WriteLine(fileNameToSaveAs); saveFaultXml = new XmlTextWriter(fileNameToSaveAs,System.Text.ASCIIEncoding.ASCII); saveFaultXml.Formatting = Formatting.Indented; saveFaultXml.WriteRaw( "<?xml version= \"1.0\" encoding=\"ASCII\"?>" ); break; } case "Unicode": { saveFaultXml = new XmlTextWriter(fileNameToSaveAs,System.Text.UnicodeEncoding.Unicode); saveFaultXml.Formatting = Formatting.Indented; saveFaultXml.WriteRaw( "<?xml version= \"1.0\" encoding=\"Unicode\"?>" ); break; } default: { saveFaultXml = new XmlTextWriter(fileNameToSaveAs,null); saveFaultXml.Formatting = Formatting.Indented; saveFaultXml.WriteRaw( "<?xml version= \"1.0\"?>" ); break; } } if(isValidationRequired) { saveFaultXml.WriteDocType("Faults",null,"faultsNew.dtd",""); } saveFaultXml.WriteStartElement("Faults"); foreach(string FaultNameAsKey in FaultTableByName.Keys) { Fault FaultToSave = faultXMLNavigator.GetFaultByName(FaultNameAsKey); ///Element = Fault saveFaultXml.WriteStartElement("Fault"); ///Attribute = Name if(FaultToSave.Name != null) saveFaultXml.WriteAttributeString("Name",FaultToSave.Name); ///Attribute = ReturnValue if(FaultToSave.ReturnValue != null) saveFaultXml.WriteAttributeString("ReturnValue",FaultToSave.ReturnValue); ///Attribute = ErrorCode if(FaultToSave.ErrorCode != null) saveFaultXml.WriteAttributeString("ErrorCode",FaultToSave.ErrorCode); if(FaultToSave.Function != null) { foreach(FaultFunction function in FaultToSave.Function) { ///Element = Function saveFaultXml.WriteStartElement("Function"); /// Attribute = Name if(function.Name != null) { saveFaultXml.WriteAttributeString("Name",function.Name.ToString()); } /// Attribute = OverrideErrorCode if(function.OverrideErrorCode != null) { saveFaultXml.WriteAttributeString("OverrideErrorCode",function.OverrideErrorCode.ToString()); } /// Attribute = OverrideReturnValue if(function.OverrideReturnValue!= null) { saveFaultXml.WriteAttributeString("OverrideReturnValue",function.OverrideReturnValue.ToString()); } /// Attribute = PassThrough if(function.PassThrough != null) { saveFaultXml.WriteAttributeString("PassThrough",function.PassThrough.ToString()); } /// Attribute = Exception if(function.Exception != null) { saveFaultXml.WriteAttributeString("Exception",function.Exception.ToString()); } /// Attribute = Allocation if(function.Allocation != null) { saveFaultXml.WriteAttributeString("Allocation",function.Allocation.ToString()); } // checkresource Tag if(function.CheckResource != null) { foreach(FaultFunctionCheckResource checkresource in function.CheckResource) { /// Element = CheckResource saveFaultXml.WriteStartElement("CheckResource"); /// Attribute = ParamIndex if(checkresource.ParamIndex != null) { saveFaultXml.WriteAttributeString("ParamIndex",checkresource.ParamIndex.ToString()); } /// Attribute = Exists if(checkresource.Exists != null) { saveFaultXml.WriteAttributeString("Exists",checkresource.Exists.ToString()); } /// end of checkresource Element saveFaultXml.WriteEndElement(); } } //matchparams tag if(function.MatchParams!= null) { foreach(FaultFunctionMatchParams matchParams in function.MatchParams) { /// Element = MatchParams saveFaultXml.WriteStartElement("MatchParams"); if(matchParams.MatchParam!= null) { foreach(FaultFunctionMatchParams matchParam in matchParams.MatchParam) { /// Element = MatchParam saveFaultXml.WriteStartElement("MatchParam"); /// Attribute = Name if(matchParam.Name != null) { saveFaultXml.WriteAttributeString("Name",matchParam.Name.ToString()); } /// Attribute = TestOperator if(matchParam.TestOperator != null) { saveFaultXml.WriteAttributeString("TestOperator",matchParam.TestOperator.ToString()); } /// Attribute = TestValue if(matchParam.TestValue != null) { saveFaultXml.WriteAttributeString("TestValue",matchParam.TestValue.ToString()); } /// Attribute = CompareAsType if(matchParam.CompareAsType != null) { saveFaultXml.WriteAttributeString("CompareAsType",matchParam.CompareAsType.ToString()); } /// Attribute = ID if(matchParam.ID != null) { saveFaultXml.WriteAttributeString("ID",matchParam.ID.ToString()); } /// end of MatchParam Element saveFaultXml.WriteEndElement(); } } /// end of MatchParams Element saveFaultXml.WriteEndElement(); } } /// end of Fault Functions Element saveFaultXml.WriteEndElement(); } /// end of Fault Element saveFaultXml.WriteEndElement(); } } //closeing Faluts Tag saveFaultXml.WriteFullEndElement(); //closing xmlwriter. saveFaultXml.Close( ); }
public void SaveTo(string filePath) { using (FileStream fileStream = new FileStream(filePath, FileMode.OpenOrCreate)) { using (XmlTextWriter writer = new XmlTextWriter(fileStream, Encoding.UTF8)) { writer.Formatting = Formatting.Indented; writer.WriteStartDocument(); writer.WriteDocType("plist", "-//Apple//DTD PLIST 1.0//EN", "http://www.apple.com/DTDs/PropertyList-1.0.dtd", null); writer.WriteStartElement("plist"); writer.WriteAttributeString("version", "1.0"); writer.WriteStartElement("dict"); WriteFloat(writer, "angle", Angle); WriteFloat(writer, "angleVariance", AngleVar); WriteInt(writer, "blendFuncDestination", (int)DestBlendFunc); WriteInt(writer, "blendFuncSource", (int)SrcBlendFunc); WriteFloat(writer, "duration", Duration); WriteFloat(writer, "emitterType", (float)Mode); WriteFloat(writer, "emissionRate", EmissionRate); WriteFloat(writer, "finishColorAlpha", EndColor.A / 255.0f); WriteFloat(writer, "finishColorBlue", EndColor.B / 255.0f); WriteFloat(writer, "finishColorGreen", EndColor.G / 255.0f); WriteFloat(writer, "finishColorRed", EndColor.R / 255.0f); WriteFloat(writer, "finishColorVarianceAlpha", EndColorVar.A / 255.0f); WriteFloat(writer, "finishColorVarianceBlue", EndColorVar.B / 255.0f); WriteFloat(writer, "finishColorVarianceGreen", EndColorVar.G / 255.0f); WriteFloat(writer, "finishColorVarianceRed", EndColorVar.R / 255.0f); WriteFloat(writer, "rotationStart", StartSpin); WriteFloat(writer, "rotationStartVariance", StartSpinVar); WriteFloat(writer, "rotationEnd", EndSpin); WriteFloat(writer, "rotationEndVariance", EndSpinVar); WriteFloat(writer, "finishParticleSize", EndSize); WriteFloat(writer, "finishParticleSizeVariance", EndSizeVar); WriteFloat(writer, "gravityx", GravityX); WriteFloat(writer, "gravityy", GravityY); WriteFloat(writer, "maxParticles", TotalParticles); WriteFloat(writer, "maxRadius", StartRadius); WriteFloat(writer, "maxRadiusVariance", StartRadiusVar); WriteFloat(writer, "minRadius", EndRadius); WriteFloat(writer, "minRadiusVariance", EndRadiusVar); WriteFloat(writer, "particleLifespan", Life); WriteFloat(writer, "particleLifespanVariance", LifeVar); WriteFloat(writer, "radialAccelVariance", RadialAccelVar); WriteFloat(writer, "radialAcceleration", RadialAccel); WriteFloat(writer, "rotatePerSecond", RotatePerSecond); WriteFloat(writer, "rotatePerSecondVariance", RotatePerSecondVar); WriteFloat(writer, "sourcePositionVariancex", PosVarX); WriteFloat(writer, "sourcePositionVariancey", PosVarY); WriteFloat(writer, "sourcePositionx", SourcePositionX); WriteFloat(writer, "sourcePositiony", SourcePositionY); WriteFloat(writer, "speed", Speed); WriteFloat(writer, "speedVariance", SpeedVar); WriteFloat(writer, "startColorAlpha", StartColor.A / 255.0f); WriteFloat(writer, "startColorBlue", StartColor.B / 255.0f); WriteFloat(writer, "startColorGreen", StartColor.G / 255.0f); WriteFloat(writer, "startColorRed", StartColor.R / 255.0f); WriteFloat(writer, "startColorVarianceAlpha", StartColorVar.A / 255.0f); WriteFloat(writer, "startColorVarianceBlue", StartColorVar.B / 255.0f); WriteFloat(writer, "startColorVarianceGreen", StartColorVar.G / 255.0f); WriteFloat(writer, "startColorVarianceRed", StartColorVar.R / 255.0f); WriteFloat(writer, "startParticleSize", StartSize); WriteFloat(writer, "startParticleSizeVariance", StartSizeVar); WriteFloat(writer, "tangentialAccelVariance", TangentialAccelVar); WriteFloat(writer, "tangentialAcceleration", TangentialAccel); WriteString(writer, "textureFileName", TexturePath); if (IsSaveTextureImageData) { if (string.IsNullOrEmpty(TextureImageData)) { if (File.Exists(TexturePath)) { var data=File.ReadAllBytes(TexturePath); MemoryStream ms=new MemoryStream(); DeflaterOutputStream outputStream = new DeflaterOutputStream(ms); outputStream.Write(data,0,data.Length); outputStream.Close(); data = ms.ToArray(); TextureImageData = Convert.ToBase64String(data); } } if (TextureImageData.Length > 0) { WriteString(writer, "textureImageData", TextureImageData); } } writer.WriteEndElement(); } fileStream.Close(); } }
/// <summary> /// Get a string that contains a complete SVG document. XML version, DOCTYPE etc are included. /// </summary> /// <returns></returns> /// <param name="compressAttributes">Should usually be set true. Causes the XML output to be optimized so that /// long attributes like styles and transformations are represented with entities.</param> /// <param name="specifyDTD">True if the SVG 1.1 DTD should be specified in the DOCTYPE of the output. Some (or all) versions of the .NET runtime have trouble /// reading this DTD, so it may be best not to specify it for now.</param> public string WriteSVGString(bool compressAttributes, bool specifyDTD) { string s; string ents = ""; XmlDocument doc = new XmlDocument(); //write out our SVG tree to the new XmlDocument WriteXmlElements(doc, null); if (compressAttributes) ents = SvgFactory.CompressXML(doc, doc.DocumentElement); //This complicated business of writing to a memory stream and then reading back out to a string //is necessary in order to specify UTF8 -- for some reason the default is UTF16 (which makes most renderers //give up) MemoryStream ms = new MemoryStream(); XmlTextWriter wr = new XmlTextWriter(ms, new UTF8Encoding()); wr.Formatting = Formatting.Indented; wr.WriteStartDocument(true); if (specifyDTD) { wr.WriteDocType("svg", "-//W3C//DTD SVG 1.1//EN", "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd", ents); } else { wr.WriteDocType("svg", null, null, ents); } doc.Save(wr); byte[] buf = ms.ToArray(); s = Encoding.UTF8.GetString(buf, 0, buf.Length); wr.Close(); return s; }
// Writes the current node into the provided XmlWriter. private void WriteNode(XmlTextWriter xtw, bool defattr) { int d = this.NodeType == XmlNodeType.None ? -1 : this.Depth; while (this.Read() && (d < this.Depth)) { switch (this.NodeType) { case XmlNodeType.Element: xtw.WriteStartElement(this.Prefix, this.LocalName, this.NamespaceURI); xtw.QuoteChar = this.QuoteChar; xtw.WriteAttributes(this, defattr); if (this.IsEmptyElement) { xtw.WriteEndElement(); } break; case XmlNodeType.Text: xtw.WriteString(this.Value); break; case XmlNodeType.Whitespace: case XmlNodeType.SignificantWhitespace: xtw.WriteWhitespace(this.Value); break; case XmlNodeType.CDATA: xtw.WriteCData(this.Value); break; case XmlNodeType.EntityReference: xtw.WriteEntityRef(this.Name); break; case XmlNodeType.XmlDeclaration: case XmlNodeType.ProcessingInstruction: xtw.WriteProcessingInstruction(this.Name, this.Value); break; case XmlNodeType.DocumentType: xtw.WriteDocType(this.Name, this.GetAttribute("PUBLIC"), this.GetAttribute("SYSTEM"), this.Value); break; case XmlNodeType.Comment: xtw.WriteComment(this.Value); break; case XmlNodeType.EndElement: xtw.WriteFullEndElement(); break; } } if (d == this.Depth && this.NodeType == XmlNodeType.EndElement) { Read(); } }
protected virtual XmlDocument CreateDomainXmlDocument(IClassMap classMap, string fileName) { ISourceMap sourceMap = classMap.GetDocSourceMap(); MemoryStream ms = new MemoryStream() ; XmlTextWriter xmlWriter = new XmlTextWriter( ms, Encoding.GetEncoding( sourceMap.GetDocEncoding() )); xmlWriter.Formatting = Formatting.Indented; xmlWriter.WriteStartDocument(false); xmlWriter.WriteDocType("Domain",null,null,null); xmlWriter.WriteComment("Serialized domain objects"); // do not localize xmlWriter.WriteStartElement(sourceMap.GetDocRoot() , null); xmlWriter.WriteEndElement(); xmlWriter.WriteEndDocument(); //Write the XML to file and close the writer xmlWriter.Flush(); string xml = Encoding.GetEncoding( "utf-8" ).GetString(ms.ToArray(),0,(int)ms.Length); xmlWriter.Close(); //TODO: ugly hack!! Do this right way to avoid extra char in the beginning!! xml = xml.Substring(1); XmlDocument xmlDocument = new XmlDocument() ; xmlDocument.LoadXml(xml); CachedXmlDocument cachedXmlDocument = new CachedXmlDocument(xmlDocument, fileName) ; cachedXmlDocuments[fileName] = cachedXmlDocument; return xmlDocument; }
private XmlTextReader PreprocessListItems(XmlTextReader xReader, PipelineContext context) { TextWriter sWriter = new StringWriter(); XmlTextWriter xWriter = new XmlTextWriter(sWriter); string attrName = "metadataFieldValue"; // Must be same as extension config, 'selector="@metadataFieldValue"' string attrValue = "fieldValue"; // default here to confirm GUI DataExtender is working - will update value below xReader.MoveToContent(); while (!xReader.EOF) { switch (xReader.NodeType) { case XmlNodeType.Element: xWriter.WriteStartElement(xReader.Prefix, xReader.LocalName, xReader.NamespaceURI); // add all list attributes back -- always START with this to NOT break the GUI xWriter.WriteAttributes(xReader, false); try { // add my custom attribute if (IsValidItem(xReader)) { string id = xReader.GetAttribute("ID"); // URI TcmUri uri = new TcmUri(id); if (uri.ItemType == ItemType.Component) { // Do Work Here.... attrValue = "your new value"; } // add new metadata field attribute xWriter.WriteAttributeString(attrName, attrValue); xReader.MoveToElement(); } } catch (Exception ex) { Trace.TraceError("EXCEPTION " + ex.Message + ex.ToString() + ex.StackTrace); } if (xReader.IsEmptyElement) { xWriter.WriteEndElement(); } break; case XmlNodeType.EndElement: xWriter.WriteEndElement(); break; case XmlNodeType.CDATA: // Copy CDATA node <![CDATA[]]> xWriter.WriteCData(xReader.Value); break; case XmlNodeType.Comment: // Copy comment node <!-- --> xWriter.WriteComment(xReader.Value); break; case XmlNodeType.DocumentType: // Copy XML documenttype xWriter.WriteDocType(xReader.Name, null, null, null); break; case XmlNodeType.EntityReference: xWriter.WriteEntityRef(xReader.Name); break; case XmlNodeType.ProcessingInstruction: xWriter.WriteProcessingInstruction(xReader.Name, xReader.Value); break; case XmlNodeType.SignificantWhitespace: xWriter.WriteWhitespace(xReader.Value); break; case XmlNodeType.Text: xWriter.WriteString(xReader.Value); break; case XmlNodeType.Whitespace: xWriter.WriteWhitespace(xReader.Value); break; } xReader.Read(); }; xWriter.Flush(); xReader = new XmlTextReader(new StringReader(sWriter.ToString())); xReader.MoveToContent(); //-> Write XML of tcm:Item out... // This is where the attribute in the config file is matched -> selector="@metadataFieldValue" // Trace.Write(sWriter.ToString() + Environment.NewLine); return xReader; }
protected virtual XmlDocument CreateObjectXmlDocument(IClassMap classMap, string fileName) { ISourceMap sourceMap = classMap.GetDocSourceMap(); MemoryStream ms = new MemoryStream() ; XmlTextWriter xmlWriter = new XmlTextWriter( ms, Encoding.GetEncoding( sourceMap.GetDocEncoding() )); xmlWriter.Formatting = Formatting.Indented; xmlWriter.WriteStartDocument(false); xmlWriter.WriteDocType("Object",null,null,null); xmlWriter.WriteComment("Serialized object"); // do not localize xmlWriter.WriteStartElement(classMap.GetDocElement(), null); xmlWriter.WriteEndElement(); xmlWriter.WriteEndDocument(); //Write the XML to file and close the writer xmlWriter.Flush(); string xml = Encoding.GetEncoding( "utf-8" ).GetString(ms.ToArray(),0,(int)ms.Length); xmlWriter.Close(); //Obs fulhack!! Jag får ett konstigt skräptecken i början!! xml = xml.Substring(1); XmlDocument xmlDocument = new XmlDocument() ; xmlDocument.LoadXml(xml); CachedXmlDocument cachedXmlDocument = new CachedXmlDocument(xmlDocument, fileName) ; cachedXmlDocuments[fileName] = cachedXmlDocument; return xmlDocument; }
/// <summary> /// Grava os dados do evento no xml /// </summary> /// <param name="objEvento">Evento de log ocorrido</param> protected override void GravarArquivo(EventosLogEventArgs objEvento) { base.GravarArquivo(objEvento); var logXml = new XmlDocument(); try { logXml.Load(CaminhoArquivo + NomeArquivo); } catch (XmlException) { if (!logXml.HasChildNodes) { var arquivoXml = new XmlTextWriter(CaminhoArquivo + NomeArquivo, Encoding.UTF8) { Formatting = Formatting.Indented }; arquivoXml.WriteStartDocument(); arquivoXml.WriteDocType("RegistroLog", null, "", "<!ELEMENT RegistroLog ANY>"); arquivoXml.WriteStartElement("RegistroLog"); arquivoXml.WriteEndElement(); arquivoXml.WriteEndDocument(); arquivoXml.Flush(); arquivoXml.Close(); } logXml.Load(CaminhoArquivo + NomeArquivo); } var root = logXml.DocumentElement; XmlNode evento = logXml.CreateElement("evento"); var dataHora = logXml.CreateAttribute("datahora"); dataHora.Value = objEvento.DataHora.ToString(CultureInfo.CurrentCulture); if (evento.Attributes != null) evento.Attributes.Append(dataHora); XmlNode tipo = logXml.CreateElement("tipolog"); tipo.InnerText = objEvento.Registro.LogTipo.ToString("G"); XmlNode origem = logXml.CreateElement("origem"); origem.InnerText = objEvento.Registro.Origem; XmlNode descricao = logXml.CreateElement("descricao"); if (string.IsNullOrWhiteSpace(objEvento.Descricao)) descricao.InnerText = objEvento.Descricao; #region Dados da Exceção XmlNode excecao = logXml.CreateElement("dadosexcecao"); XmlNode mensagem = logXml.CreateElement("mensagem"); mensagem.InnerText = objEvento.Exception.Message; XmlNode source = logXml.CreateElement("source"); source.InnerText = objEvento.Exception.Source; XmlNode stackTrace = logXml.CreateElement("stacktrace"); stackTrace.InnerText = objEvento.Exception.StackTrace; XmlNode targetSite = logXml.CreateElement("targetsite"); targetSite.InnerText = objEvento.Exception.TargetSite.ToString(); excecao.AppendChild(mensagem); excecao.AppendChild(source); excecao.AppendChild(stackTrace); excecao.AppendChild(targetSite); #endregion evento.AppendChild(tipo); evento.AppendChild(descricao); evento.AppendChild(excecao); if (root != null) root.AppendChild(evento); logXml.Save(CaminhoArquivo + NomeArquivo); }
private void CreateEmptyConfigFile(string newFileName) { XmlTextWriter writer = new XmlTextWriter (newFileName, System.Text.Encoding.UTF8); writer.Formatting = Formatting.Indented; writer.WriteStartDocument (false); writer.WriteDocType ("SIBUILDER", null, this.dtdName, null); writer.WriteStartElement ("SIBUILDER"); writer.WriteEndElement (); writer.WriteEndDocument (); writer.Flush(); writer.Close(); }
private void saveRuncommandsXML ( string pathTofile = "" ) { if ( pathTofile == "" ) pathTofile = this. FileXMLpath; File. Delete ( pathTofile ); try { using ( XmlTextWriter myXmlTextWriter = new XmlTextWriter ( pathTofile, null ) ) { myXmlTextWriter. Formatting = Formatting. Indented; myXmlTextWriter. WriteStartDocument ( false ); myXmlTextWriter. WriteDocType ( "CommandRepository", null, null, null ); myXmlTextWriter. WriteComment ( "This file represents a repository of Quicky Runcommands" ); myXmlTextWriter. WriteStartElement ( "CommandRepository" ); myXmlTextWriter. WriteAttributeString ( "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance" ); myXmlTextWriter. WriteAttributeString ( "xsi:noNamespaceSchemaLocation", "CommandRepository.xsd" ); myXmlTextWriter. WriteAttributeString ( "Name", this. Name ); foreach ( RunCommand rc in this. Commands ) { myXmlTextWriter. WriteStartElement ( "RunCommand", null ); myXmlTextWriter. WriteAttributeString ( "Quicky", rc. Quicky ); myXmlTextWriter. WriteAttributeString ( "Type", ( ( int ) rc. Type ). ToString ( ) ); myXmlTextWriter. WriteAttributeString ( "Description", rc. Desctiption ); myXmlTextWriter. WriteAttributeString ( "Command", rc. Command ); myXmlTextWriter. WriteAttributeString ( "Arguments", rc. Arguments ); myXmlTextWriter. WriteAttributeString ( "IconLocation", rc. IconLocation ); myXmlTextWriter. WriteEndElement ( ); } myXmlTextWriter. WriteEndElement ( ); //Write the XML to file and close the writer xsi:noNamespaceSchemaLocation myXmlTextWriter. Flush ( ); myXmlTextWriter. Close ( ); } } catch ( Exception ) { throw; } }
/// <summary> /// Create an XmlTextWriter for writing an html document. /// </summary> /// <param name="file">The file which will contain the document.</param> /// <param name="title">The title of the document.</param> /// <param name="headerClass">The class for the header element.</param> /// <returns>The XmlTextWriter for the document.</returns> private static XmlTextWriter StartHtmlWriter(string file, string title, string headerClass) { XmlTextWriter writer = new XmlTextWriter(file, Encoding.UTF8); writer.Formatting = Formatting.Indented; writer.WriteDocType("html", "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", null); writer.WriteStartElement("html", XHtmlNamespace); writer.WriteStartElement("head"); writer.WriteStartElement("link"); writer.WriteAttributeString("rel", "stylesheet"); writer.WriteAttributeString("type", "text/css"); writer.WriteAttributeString("href", "style.css"); writer.WriteEndElement(); writer.WriteStartElement("title"); writer.WriteString(title); writer.WriteEndElement(); // end head element writer.WriteEndElement(); writer.WriteStartElement("body"); writer.WriteAttributeString("class", "schema"); writer.WriteStartElement("div"); writer.WriteAttributeString("class", headerClass); writer.WriteStartElement("h1"); writer.WriteAttributeString("class", "schema"); writer.WriteString(title); writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteStartElement("div"); writer.WriteAttributeString("class", "schemaMain"); return writer; }