public WriteStartAttribute ( string prefix, string localName, string ns ) : void | ||
prefix | string | |
localName | string | |
ns | string | |
리턴 | void |
private string GetExpectedMods(IntegrationResult result) { System.IO.StringWriter sw = new System.IO.StringWriter(); System.Xml.XmlTextWriter cbiw = new System.Xml.XmlTextWriter(sw); cbiw.Formatting = System.Xml.Formatting.Indented; cbiw.WriteStartElement("Build"); cbiw.WriteStartAttribute("BuildDate"); cbiw.WriteValue(DateUtil.FormatDate(result.EndTime)); cbiw.WriteStartAttribute("Success"); cbiw.WriteValue(result.Succeeded.ToString()); cbiw.WriteStartAttribute("Label"); cbiw.WriteValue(result.Label); if (result.Modifications.Length > 0) { cbiw.WriteStartElement("modifications"); for (int i = 0; i < result.Modifications.Length; i++) { result.Modifications[i].ToXml(cbiw); } cbiw.WriteEndElement(); } cbiw.WriteEndElement(); return(sw.ToString()); }
static void WriteMyAssetSet(FileInfo[] files) { string shortfile; XmlTextWriter xmlwriter = new XmlTextWriter("MyAssetSet.xml", null); xmlwriter.Formatting = System.Xml.Formatting.Indented; xmlwriter.IndentChar = ' '; xmlwriter.Indentation = 2; xmlwriter.WriteStartElement("Nini"); foreach (FileInfo f in files) { shortfile = Path.GetFileNameWithoutExtension(f.FullName); xmlwriter.WriteStartElement("Section"); xmlwriter.WriteStartAttribute("Name"); xmlwriter.WriteValue(shortfile); xmlwriter.WriteEndAttribute(); WriteKey(xmlwriter, "assetID", shortfile); WriteKey(xmlwriter, "name", shortfile); WriteKey(xmlwriter, "assetType", "0"); WriteKey(xmlwriter, "inventoryType", "0"); WriteKey(xmlwriter, "fileName", f.Name); xmlwriter.WriteEndElement(); } xmlwriter.WriteEndElement(); xmlwriter.Close(); }
/// <summary> /// 写 XML /// </summary> public void WriteXml() { // 构造写入类. // 第一个参数为 文件名 // 第二个参数为编码方式. XmlTextWriter writer = new XmlTextWriter(XML_FILE_NAME, Encoding.UTF8); //使用自动缩进便于阅读 writer.Formatting = Formatting.Indented; // 书写版本为“1.0”的 XML 声明 writer.WriteStartDocument(); // 写注释 writer.WriteComment("XML文件写入的例子!"); //写入根元素 writer.WriteStartElement("items"); // 加入属性: type="IT" writer.WriteStartAttribute("type"); writer.WriteString("information"); writer.WriteEndAttribute(); writer.WriteStartAttribute("keyword"); writer.WriteString("Database"); writer.WriteEndAttribute(); // 加入子元素: <title>SQL Server</title> 这种方式的。 writer.WriteElementString("title", "SQL Server"); writer.WriteElementString("title", "Oracle"); writer.WriteElementString("title", "MySQL"); //关闭根元素,并书写结束标签 writer.WriteEndElement(); // 关闭任何打开的元素或属性 writer.WriteEndDocument(); //将XML写入文件并且关闭XmlTextWriter writer.Close(); }
public static void Main(string[] args) { XmlTextWriter xmlTextWriter = new XmlTextWriter(Console.Out); xmlTextWriter.WriteStartDocument(); xmlTextWriter.WriteString("articulo1"); xmlTextWriter.WriteStartAttribute("nombre"); xmlTextWriter.WriteString("Articulo uno"); xmlTextWriter.Close(); }
public void SaveToFile(string text1) { XmlTextWriter writer = null; writer = new XmlTextWriter(text1, Encoding.Default); writer.Formatting = Formatting.Indented; writer.WriteStartDocument(); writer.WriteStartElement("root"); writer.WriteStartElement("BetSuccessSwitching"); writer.WriteStartAttribute("IsBetSuccessSwitchingEnable"); writer.WriteValue(Conversion.Val(this._isBetSuccessSwitchingEnable).ToString()); writer.WriteEndAttribute(); writer.WriteStartAttribute("BetSuccessSwitchingValue"); writer.WriteValue(this._objBetSuccessSwitchingOpotion.get_SwitchingValue().ToString()); writer.WriteEndAttribute(); writer.WriteEndElement(); writer.Flush(); writer.Close(); }
public void addAtributeToXml(XmlTextWriter t, string name, string text) { if (text == null) { text = ""; } t.WriteStartAttribute(name); t.WriteString(text); t.WriteEndAttribute(); }
public static void Save() { string file = Path.Combine(Paths.ConfigDirectory, ConfigFile); XmlTextWriter xmlWriter = new XmlTextWriter(file, Encoding.UTF8); xmlWriter.Formatting = Formatting.Indented; xmlWriter.WriteStartElement("proxy-settings"); // Proxy xmlWriter.WriteStartElement("proxy"); // Enabled xmlWriter.WriteStartAttribute("enabled"); xmlWriter.WriteString(EnableProxy.ToString()); xmlWriter.WriteEndAttribute(); if (EnableProxy == true) { // Set Host xmlWriter.WriteStartAttribute("host"); xmlWriter.WriteString(Host); xmlWriter.WriteEndAttribute(); // Set Port xmlWriter.WriteStartAttribute("port"); xmlWriter.WriteString(Port.ToString()); xmlWriter.WriteEndAttribute(); } xmlWriter.WriteEndElement(); // Proxy Auth xmlWriter.WriteStartElement("auth"); // Enabled xmlWriter.WriteStartAttribute("enabled"); xmlWriter.WriteString(UseProxyAuth.ToString()); xmlWriter.WriteEndAttribute(); if (UseProxyAuth == true) { // Set Host xmlWriter.WriteStartAttribute("username"); xmlWriter.WriteString(Username); xmlWriter.WriteEndAttribute(); // Set Port xmlWriter.WriteStartAttribute("password"); xmlWriter.WriteString(Password); xmlWriter.WriteEndAttribute(); } xmlWriter.WriteEndElement(); xmlWriter.WriteEndElement(); xmlWriter.Close(); }
public static void SaveParameters() { try { XmlTextWriter writer = new XmlTextWriter("params.xml", System.Text.Encoding.UTF8); writer.Formatting = Formatting.Indented; writer.WriteStartDocument(); writer.WriteStartElement("RegionEditor"); if (MulPath != "") { writer.WriteStartElement("mulpath"); writer.WriteStartAttribute("path"); writer.WriteValue(_MulPath); writer.WriteEndAttribute(); writer.WriteEndElement(); } if (RegionsFile != "") { writer.WriteStartElement("script"); writer.WriteStartAttribute("file"); writer.WriteValue(_RegionsFile); writer.WriteEndAttribute(); writer.WriteEndElement(); } if (Compatibility) { writer.WriteStartElement("client"); writer.WriteStartAttribute("compatibilitymode"); writer.WriteValue(Compatibility); writer.WriteEndAttribute(); writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteEndDocument(); writer.Close(); } catch { } }
/// <summary> /// Encodes any special characters in the xml string. /// </summary> public static string Encode(string xml, char quoteCharacter) { XmlEncoderTextWriter encoderWriter = new XmlEncoderTextWriter(); using (XmlTextWriter writer = new XmlTextWriter(encoderWriter)) { writer.WriteStartElement("root"); writer.WriteStartAttribute("attribute"); writer.QuoteChar = quoteCharacter; encoderWriter.BeginMarkup(); writer.WriteString(xml); return encoderWriter.Markup; } }
public static void Save(string file) { using (var writer = new XmlTextWriter(file, Encoding.UTF8)) { writer.WriteStartElement("configuration"); writer.WriteStartElement("connectionstring"); writer.WriteStartAttribute("ip"); writer.WriteString(IP); writer.WriteEndAttribute(); writer.WriteStartAttribute("user"); writer.WriteString(User); writer.WriteEndAttribute(); writer.WriteStartAttribute("password"); writer.WriteString(Password); writer.WriteEndAttribute(); writer.WriteStartAttribute("database"); writer.WriteString(Database); writer.WriteEndAttribute(); } }
private static void TraverseRootDirectoryRecursively(XmlTextWriter writer, DirectoryInfo rootDirectory) { if (!rootDirectory.GetFiles().Any() && !rootDirectory.GetDirectories().Any()) { return; } writer.WriteStartElement("dir"); writer.WriteStartAttribute("name", rootDirectory.Name); foreach (var file in rootDirectory.GetFiles()) { writer.WriteStartElement("file"); writer.WriteStartAttribute("name", file.Name); writer.WriteEndElement(); } foreach (var directory in rootDirectory.GetDirectories()) { TraverseRootDirectoryRecursively(writer, directory); } writer.WriteEndElement(); }
/// <summary> /// Сохранение истории задачи в отдельный XML-файл /// </summary> /// <param name="taskname">Название задачи</param> /// <param name="his">История задачи</param> /// <param name="fname">Полный путь и имя файла для сохранения</param> public static void SaveTaskHistoryToXMLFile(string taskname, THistory[] his, string fname) { XmlTextWriter file = new XmlTextWriter(fname, Encoding.UTF8); file.WriteStartDocument(); file.WriteComment("Definition of task history data"); file.WriteStartElement("history"); file.WriteStartAttribute("taskname"); file.WriteValue(taskname); for (int i = 0; i < his.Length; i++) { file.WriteStartElement("helement"); file.WriteStartAttribute("date"); file.WriteValue(his[i].Date); file.WriteStartAttribute("type"); file.WriteValue(his[i].Type.ToString()); file.WriteStartAttribute("value"); file.WriteValue(his[i].Value); file.WriteEndElement(); } file.WriteEndElement(); file.Close(); }
/// <summary> /// Запись кэша меток в отдельный XML файл /// </summary> /// <param name="buf">Кэш меток</param> /// <param name="fname">Полный путь и название файла для сохранения</param> public static void SaveLabelsCacheToXMLFile(LabelsCache buf, string fname) { XmlTextWriter file = new XmlTextWriter(fname, Encoding.UTF8); file.WriteStartDocument(); file.WriteComment("Definition of labels cache data"); file.WriteStartElement("labels"); for (int i = 0; i < buf.GetLabelsCount; i++) { file.WriteStartElement("label"); file.WriteStartAttribute("value"); file.WriteValue(buf[i]); file.WriteEndElement(); } file.WriteEndElement(); file.Close(); }
/// <summary> /// Constructs the ticket payload. /// </summary> /// <param name="rootElement"></param> /// <param name="ticketType"></param> /// <param name="keyValueDictionary"></param> /// <returns></returns> public string writeTicketLoad(string rootElement, string ticketType, Dictionary<string, object> keyValueDictionary) { try { StringWriter stringWriter = new StringWriter(); XmlTextWriter xmlWriter = new XmlTextWriter(stringWriter); //xmlWriter.Formatting = Formatting.Indented; //xmlWriter.Indentation = indentation; // write root element xmlWriter.WriteStartElement(rootElement); xmlWriter.WriteAttributeString("xmlns", "ns", null, ticketNS); // write ticket type xmlWriter.WriteStartAttribute("ticketType"); xmlWriter.WriteString(ticketType); xmlWriter.WriteEndAttribute(); foreach (string s in keyValueDictionary.Keys) { xmlWriter.WriteStartElement(s); object value = new object(); keyValueDictionary.TryGetValue(s, out value); xmlWriter.WriteString(value.ToString()); xmlWriter.WriteEndElement(); } xmlWriter.WriteEndElement(); return stringWriter.ToString(); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); } return null; }
static void WriteMySiteLibraryFolders(string folderID) { XmlTextWriter xmlwriter = new XmlTextWriter("MySiteLibraryFolders.xml", null); xmlwriter.Formatting = System.Xml.Formatting.Indented; xmlwriter.IndentChar = ' '; xmlwriter.Indentation = 2; xmlwriter.WriteStartElement("Nini"); xmlwriter.WriteStartElement("Section"); xmlwriter.WriteStartAttribute("Name"); xmlwriter.WriteValue("MySiteLibraryFolder"); xmlwriter.WriteEndAttribute(); WriteKey(xmlwriter, "folderID", folderID); WriteKey(xmlwriter, "parentFolderID", "00000112-000f-0000-0000-000100bba000"); WriteKey(xmlwriter, "name", "MySiteLibraryFolder"); WriteKey(xmlwriter, "type", "0"); xmlwriter.WriteEndElement(); xmlwriter.WriteEndElement(); xmlwriter.Close(); }
private void GenerateSiteMap(HttpContext context) { context.Response.Cache.SetExpires(DateTime.Now.AddMinutes(20)); context.Response.Cache.SetCacheability(HttpCacheability.Public); context.Response.ContentType = "application/xml"; Encoding encoding = new UTF8Encoding(); context.Response.ContentEncoding = encoding; using (XmlTextWriter xmlTextWriter = new XmlTextWriter(context.Response.OutputStream, encoding)) { xmlTextWriter.Formatting = Formatting.Indented; xmlTextWriter.WriteStartDocument(); xmlTextWriter.WriteStartElement("urlset"); xmlTextWriter.WriteStartAttribute("xmlns"); xmlTextWriter.WriteValue("http://www.sitemaps.org/schemas/sitemap/0.9"); xmlTextWriter.WriteEndAttribute(); AddUrls(context, xmlTextWriter); xmlTextWriter.WriteEndElement(); //urlset //end of document xmlTextWriter.WriteEndDocument(); } }
private void CommandBinding_NewCmdExecuted(object sender, System.Windows.Input.ExecutedRoutedEventArgs e) { MogitorsRoot mogRoot = MogitorsRoot.Instance; if (!(mogRoot.TerminateScene())) return; ProjectOptions opt = mogRoot.ProjectOptions; opt.IsNewProject = true; opt.ProjectName = ""; opt.ProjectDir = MogitorsSystem.Instance.ProjectsDirectory; opt.SceneManagerName = "OctreeSceneManager"; opt.TerrainDirectory = "Terrain"; opt.ResourceDirectories.Clear(); opt.Cameras.Clear(); opt.SelectionBBColourForSerializer = Color.FromRgb(255, 255, 255); opt.HighlightBBColourForSerializer = Color.FromRgb(232, 48, 48); SettingsDialog dlg = new SettingsDialog(opt); if (dlg.ShowDialog() == true) { string fileName = MogitorsSystem.Instance.CombinePath(mogRoot.ProjectOptions.ProjectDir, mogRoot.ProjectOptions.ProjectName + ".mogscene"); fileName = MogitorsSystem.Instance.GetFullPath(fileName); XmlTextWriter textWriter = new XmlTextWriter(fileName, System.Text.Encoding.Unicode); textWriter.Formatting = Formatting.Indented; textWriter.WriteStartDocument(); // XML Root textWriter.WriteStartElement("MogitorScene"); // Write project options mogRoot.WriteProjectOptions(textWriter, true); // Write new scene definition textWriter.WriteStartElement("Object"); textWriter.WriteStartAttribute("Type"); textWriter.WriteValue(mogRoot.ProjectOptions.SceneManagerName); textWriter.WriteEndAttribute(); textWriter.WriteStartAttribute("SceneManagerType"); textWriter.WriteValue(mogRoot.ProjectOptions.SceneManagerName); textWriter.WriteEndAttribute(); textWriter.WriteStartAttribute("Name"); textWriter.WriteValue("SceneManager"); textWriter.WriteEndAttribute(); textWriter.WriteStartAttribute("Ambient"); textWriter.WriteValue("1.000 1.000 1.000"); textWriter.WriteEndAttribute(); textWriter.WriteEndElement(); textWriter.WriteEndElement(); textWriter.WriteEndDocument(); textWriter.Close(); mogRoot.LoadScene(fileName); } this.statusString.Text = "New scene created"; }
public void SaveToFile(string text1) { XmlTextWriter writer = null; writer = new XmlTextWriter(text1, Encoding.Default); writer.Formatting = Formatting.Indented; writer.WriteStartDocument(); writer.WriteStartElement("root"); foreach (WebsiteBetStyle style in this._objDefaultWebsiteBetStyleList.get_SourceList()) { writer.WriteStartElement("WebsiteBetStyle"); writer.WriteStartAttribute("Website"); writer.WriteValue(style.get_Website()); writer.WriteEndAttribute(); writer.WriteStartAttribute("BetStyle"); writer.WriteValue(Conversion.Val(style.get_BetStyle()).ToString()); writer.WriteEndAttribute(); writer.WriteStartAttribute("BetValue"); writer.WriteValue(Conversion.Val(style.get_BetValue()).ToString()); writer.WriteEndAttribute(); writer.WriteEndElement(); } writer.WriteStartElement("Range"); writer.WriteStartAttribute("MemberRange"); writer.WriteValue(Conversion.Val(this._objMemberRange).ToString()); writer.WriteEndAttribute(); writer.WriteEndElement(); writer.WriteStartElement("GlobalFollowOddsOption"); writer.WriteStartAttribute("FollowOddsOption"); writer.WriteValue(Conversion.Val(this._objGlobalFollowOddsOption.get_FollowOddsOption()).ToString()); writer.WriteEndAttribute(); writer.WriteStartAttribute("FollowOddsOptionValue"); writer.WriteValue(this._objGlobalFollowOddsOption.get_OddsValue().ToString()); writer.WriteEndAttribute(); writer.WriteEndElement(); writer.WriteStartElement("GlobalBetFollowMethod"); writer.WriteStartAttribute("BetFollowMethod"); writer.WriteValue(Conversion.Val(this._objGlobalBetFollowMethod).ToString()); writer.WriteEndAttribute(); writer.WriteEndElement(); writer.WriteStartElement("GlobalBetTargetCollection"); writer.WriteStartAttribute("IsToBetAll"); writer.WriteValue(Conversion.Val(this._objGlobalBetTargetCol.IsToBetAll).ToString()); writer.WriteEndAttribute(); writer.WriteStartAttribute("IsToBetFTPut"); writer.WriteValue(Conversion.Val(this._objGlobalBetTargetCol.IsToBetFTPut).ToString()); writer.WriteEndAttribute(); writer.WriteStartAttribute("IsToBetFTEat"); writer.WriteValue(Conversion.Val(this._objGlobalBetTargetCol.IsToBetFTEat).ToString()); writer.WriteEndAttribute(); writer.WriteStartAttribute("IsToBetFTOver"); writer.WriteValue(Conversion.Val(this._objGlobalBetTargetCol.IsToBetFTOver).ToString()); writer.WriteEndAttribute(); writer.WriteStartAttribute("IsToBetFTUnder"); writer.WriteValue(Conversion.Val(this._objGlobalBetTargetCol.IsToBetFTUnder).ToString()); writer.WriteEndAttribute(); writer.WriteStartAttribute("IsToBetHalfPut"); writer.WriteValue(Conversion.Val(this._objGlobalBetTargetCol.IsToBetHalfPut).ToString()); writer.WriteEndAttribute(); writer.WriteStartAttribute("IsToBetHalfEat"); writer.WriteValue(Conversion.Val(this._objGlobalBetTargetCol.IsToBetHalfEat).ToString()); writer.WriteEndAttribute(); writer.WriteStartAttribute("IsToBetHalfOver"); writer.WriteValue(Conversion.Val(this._objGlobalBetTargetCol.IsToBetHalfOver).ToString()); writer.WriteEndAttribute(); writer.WriteStartAttribute("IsToBetHalfUnder"); writer.WriteValue(Conversion.Val(this._objGlobalBetTargetCol.IsToBetHalfUnder).ToString()); writer.WriteEndAttribute(); writer.WriteEndElement(); writer.WriteStartElement("GlobalMinFollowLimit"); writer.WriteStartAttribute("MinFollowLimit"); writer.WriteValue(this._decGlobalMinFollowLimit.ToString()); writer.WriteEndAttribute(); writer.WriteEndElement(); writer.WriteStartElement("GlobalMaxFollowLimit"); writer.WriteStartAttribute("MaxFollowLimit"); writer.WriteValue(this._decGlobalMaxFollowLimit.ToString()); writer.WriteEndAttribute(); writer.WriteEndElement(); writer.WriteStartElement("IsGlobalFollowToSameSportBook"); writer.WriteStartAttribute("IsFollowToSameSportBook"); writer.WriteValue(Conversion.Val(this._isGlobalFollowToSameSportBook)); writer.WriteEndAttribute(); writer.WriteEndElement(); foreach (Member member in this._objMemberList) { writer.WriteStartElement("Member"); writer.WriteStartAttribute("FollowTarget"); writer.WriteValue(Conversion.Val(member.get_FollowTarget())); writer.WriteEndAttribute(); writer.WriteStartAttribute("Name"); writer.WriteValue(member.get_Name().ToString()); writer.WriteEndAttribute(); writer.WriteStartAttribute("AgentFollowOddsOptionType"); writer.WriteValue(Conversion.Val(member.get_AgentFollowOddsOpt().get_FollowOddsOption()).ToString()); writer.WriteEndAttribute(); writer.WriteStartAttribute("AgentFollowOddsOptionValue"); writer.WriteValue(member.get_AgentFollowOddsOpt().get_OddsValue().ToString()); writer.WriteEndAttribute(); writer.WriteStartAttribute("FollowOddsOptionType"); writer.WriteValue(Conversion.Val(member.get_FollowOddsOpt().get_FollowOddsOption()).ToString()); writer.WriteEndAttribute(); writer.WriteStartAttribute("FollowOddsOptionValue"); writer.WriteValue(member.get_FollowOddsOpt().get_OddsValue().ToString()); writer.WriteEndAttribute(); writer.WriteStartAttribute("BetFollowMethod"); writer.WriteValue(Conversion.Val(member.get_BetFollowMethod()).ToString()); writer.WriteEndAttribute(); writer.WriteStartAttribute("MinFollowLimit"); writer.WriteValue(member.get_MinFollowLimit().ToString()); writer.WriteEndAttribute(); writer.WriteStartAttribute("MaxFollowLimit"); writer.WriteValue(member.get_MaxFollowLimit().ToString()); writer.WriteEndAttribute(); writer.WriteStartAttribute("IsFollowToSameSportBook"); writer.WriteValue(Conversion.Val(member.get_IsFollowToSameSportBook())); writer.WriteEndAttribute(); writer.WriteStartAttribute("IsToBetAll"); writer.WriteValue(Conversion.Val(member.get_BetTargetCol().IsToBetAll).ToString()); writer.WriteEndAttribute(); writer.WriteStartAttribute("IsToBetFTPut"); writer.WriteValue(Conversion.Val(member.get_BetTargetCol().IsToBetFTPut).ToString()); writer.WriteEndAttribute(); writer.WriteStartAttribute("IsToBetFTEat"); writer.WriteValue(Conversion.Val(member.get_BetTargetCol().IsToBetFTEat).ToString()); writer.WriteEndAttribute(); writer.WriteStartAttribute("IsToBetFTOver"); writer.WriteValue(Conversion.Val(member.get_BetTargetCol().IsToBetFTOver).ToString()); writer.WriteEndAttribute(); writer.WriteStartAttribute("IsToBetFTUnder"); writer.WriteValue(Conversion.Val(member.get_BetTargetCol().IsToBetFTUnder).ToString()); writer.WriteEndAttribute(); writer.WriteStartAttribute("IsToBetHalfPut"); writer.WriteValue(Conversion.Val(member.get_BetTargetCol().IsToBetHalfPut).ToString()); writer.WriteEndAttribute(); writer.WriteStartAttribute("IsToBetHalfEat"); writer.WriteValue(Conversion.Val(member.get_BetTargetCol().IsToBetHalfEat).ToString()); writer.WriteEndAttribute(); writer.WriteStartAttribute("IsToBetHalfOver"); writer.WriteValue(Conversion.Val(member.get_BetTargetCol().IsToBetHalfOver).ToString()); writer.WriteEndAttribute(); writer.WriteStartAttribute("IsToBetHalfUnder"); writer.WriteValue(Conversion.Val(member.get_BetTargetCol().IsToBetHalfUnder).ToString()); writer.WriteEndAttribute(); foreach (WebsiteBetStyle style in member.get_WebsiteBetStyleList().get_SourceList()) { writer.WriteStartElement("MemberWebsiteBetStyle"); writer.WriteStartAttribute("Website"); writer.WriteValue(style.get_Website()); writer.WriteEndAttribute(); writer.WriteStartAttribute("BetStyle"); writer.WriteValue(Conversion.Val(style.get_BetStyle()).ToString()); writer.WriteEndAttribute(); writer.WriteStartAttribute("BetValue"); writer.WriteValue(Conversion.Val(style.get_BetValue()).ToString()); writer.WriteEndAttribute(); writer.WriteEndElement(); } writer.WriteEndElement(); } writer.WriteEndElement(); writer.Flush(); writer.Close(); this.ForceWebsiteBetStyleToFixed(); }
public void Scan() { DirectoryInfo[] albums = null; DirectoryInfo root = new DirectoryInfo(this.rootFolder); albums = root.GetDirectories(); //Object, that writes the output file XmlTextWriter textWriter = new XmlTextWriter(this.filename, null); textWriter.Formatting = Formatting.Indented; textWriter.WriteStartElement("featureset"); foreach (DirectoryInfo d in albums) { FileInfo[] files = d.GetFiles(); //Writing new album tag textWriter.WriteStartElement("album"); textWriter.WriteStartAttribute("name"); textWriter.WriteValue(d.Name); textWriter.WriteEndAttribute(); textWriter.WriteStartAttribute("author"); textWriter.WriteValue(d.Name); textWriter.WriteEndAttribute(); textWriter.WriteStartAttribute("imageUrl"); textWriter.WriteValue("images\\" + d.Name + "\\" + d.Name + ".jpg"); textWriter.WriteEndAttribute(); textWriter.WriteStartAttribute("link"); textWriter.WriteValue("#"); textWriter.WriteEndAttribute(); foreach (FileInfo file in files) { if (file.Extension == ".mp3") { TagLib.File f = TagLib.File.Create(file.FullName); //Writing Song-tag textWriter.WriteStartElement("song"); //Writing name attribute textWriter.WriteStartAttribute("name"); if (f.Tag.AlbumArtists.Length > 0 && f.Tag.Title != null) { textWriter.WriteValue(f.Tag.AlbumArtists[0] + " - " + f.Tag.Title); } else if (f.Tag.Title != null) { textWriter.WriteValue(f.Tag.Title); } else { textWriter.WriteValue(""); } textWriter.WriteEndAttribute(); //---------------------------------- //writing duration attribute textWriter.WriteStartAttribute("duration"); textWriter.WriteValue(f.Properties.Duration.Minutes.ToString() + " : " + f.Properties.Duration.Seconds.ToString()); textWriter.WriteEndAttribute(); //------------------------------------------------- //writing buy attribute textWriter.WriteStartAttribute("buy"); textWriter.WriteValue("false"); textWriter.WriteEndAttribute(); //-------------------------------- //writing download attribute textWriter.WriteStartAttribute("download"); textWriter.WriteValue(true); textWriter.WriteEndAttribute(); //-------------------------------- //writing buyLink attribute textWriter.WriteStartAttribute("buyLink"); textWriter.WriteValue("http://www.flabell.com"); textWriter.WriteEndAttribute(); //-------------------------------- //writing downloadSource attribute textWriter.WriteStartAttribute("downloadSource"); textWriter.WriteValue("player/songs/" + file.Name); textWriter.WriteEndAttribute(); //-------------------------------- textWriter.WriteValue("songs/" + file.Name); textWriter.WriteEndElement(); } } //textWriter.WriteEndAttribute(); textWriter.WriteEndElement(); } textWriter.WriteEndElement(); textWriter.Close(); }
/// Generate Xml Request public string GenerateXml() { string xml; StringWriter strStream = new StringWriter(); XmlTextWriter xmlWriter = new XmlTextWriter(strStream); // Start Tag <tag> xmlWriter.WriteStartElement(null, this.tag, null); // Attributes foreach (string key in this.xmlAttributes.Keys) { xmlWriter.WriteStartAttribute(null, key, null); xmlWriter.WriteString(this.xmlAttributes[key].ToString()); xmlWriter.WriteEndAttribute(); } // Message Body string text = xmlText.ToString(); if (text != "") { string bodyB64 = TextUtils.Base64Encode(text); xmlWriter.WriteString(bodyB64); } // End Tag </tag> xmlWriter.WriteEndElement(); // XML -> String xml = strStream.ToString(); // Close Xml Stream xmlWriter.Close(); return(xml); }
/// <summary> /// Writing data in an XML format. /// </summary> /// <param name="fileName"></param> private void SaveToXmlFile(string fileName) { int totalCount = StringRefs.Count(); int count = 0; int lastProgress = -1; XmlTextWriter xr = new XmlTextWriter(fileName, Encoding.UTF8); xr.Formatting = Formatting.Indented; xr.Indentation = 4; xr.WriteStartDocument(); xr.WriteStartElement("tlkFile"); xr.WriteAttributeString("TLKToolVersion", App.GetVersion()); xr.WriteComment("Male entries section begin"); foreach (var s in StringRefs) { if (s.position == Header.MaleEntryCount) { xr.WriteComment("Male entries section end"); xr.WriteComment("Female entries section begin"); } xr.WriteStartElement("String"); xr.WriteStartAttribute("id"); xr.WriteValue(s.StringID); xr.WriteEndAttribute(); if (s.BitOffset < 0) { xr.WriteStartAttribute("calculatedID"); xr.WriteValue(-(Int32.MinValue - s.StringID)); xr.WriteEndAttribute(); xr.WriteString("-1"); } else xr.WriteString(s.Data); xr.WriteEndElement(); // </string> int progress = (++count * 100) / totalCount; if (progress > lastProgress) { lastProgress = progress; OnProgressChanged(lastProgress); } } xr.WriteComment("Female entries section end"); xr.WriteEndElement(); // </tlkFile> xr.Flush(); xr.Close(); }
/// <summary> /// Creates a new properties files. /// </summary> private void Create() { if (TracingHelper.TraceEnabled) TracingHelper.Write(sName); XmlTextWriter writer = new XmlTextWriter(sFileProperties, null); writer.Formatting = Formatting.Indented; writer.Indentation=4; writer.WriteStartDocument(); writer.WriteComment("SharpHSQL Configuration"); writer.WriteProcessingInstruction("Instruction","Configuration Record"); writer.WriteStartElement("Properties",""); writer.WriteStartAttribute("LogFile",""); writer.WriteString(sFileScript); writer.WriteEndAttribute(); writer.WriteStartAttribute("DataFile",""); writer.WriteString(sFileCache); writer.WriteEndAttribute(); writer.WriteStartAttribute("Backup",""); writer.WriteString(sFileBackup); writer.WriteEndAttribute(); writer.WriteStartAttribute("Version", Assembly.GetExecutingAssembly().GetName().Version.ToString() ); writer.WriteString("1.0"); writer.WriteEndAttribute(); writer.WriteStartAttribute("ReadOnly",""); writer.WriteString("false"); writer.WriteEndAttribute(); writer.WriteStartAttribute("Modified",""); writer.WriteString("no"); writer.WriteEndElement(); writer.WriteEndDocument(); writer.Flush(); writer.Close(); SaveProperties(); }
// Returns the current element and its descendants or an attribute as a string. public virtual string ReadOuterXml() { if (ReadState != ReadState.Interactive) { return string.Empty; } if ((this.NodeType != XmlNodeType.Attribute) && (this.NodeType != XmlNodeType.Element)) { Read(); return string.Empty; } StringWriter sw = new StringWriter(CultureInfo.InvariantCulture); XmlTextWriter xtw = new XmlTextWriter(sw); try { SetNamespacesFlag(xtw); if (this.NodeType == XmlNodeType.Attribute) { xtw.WriteStartAttribute(this.Prefix, this.LocalName, this.NamespaceURI); WriteAttributeValue(xtw); xtw.WriteEndAttribute(); } else { xtw.WriteNode(this, false); } } finally { xtw.Close(); } return sw.ToString(); }
/// <summary> /// Saves the listeners to an XML writer. /// </summary> /// <param name="writer">The XML writer to save the users to.</param> private void SaveListeners(XmlTextWriter writer) { writer.WriteStartElement("Listeners"); lock (Parent) { for (int i = 0; i < Parent.ListenerCount; i++) { writer.WriteStartElement("listener"); // Write the type, eg 'Org.Mentalis.Proxy.Http.HttpListener' writer.WriteStartAttribute("", "type", ""); writer.WriteString(Parent[i].GetType().FullName); writer.WriteEndAttribute(); // Write the construction string writer.WriteStartAttribute("", "value", ""); writer.WriteString(Parent[i].ConstructString); writer.WriteEndAttribute(); writer.WriteEndElement(); } } writer.WriteEndElement(); }
/// <summary> /// 写xml文件 /// </summary> public static void WriteXml(string shellTypeName, string basePathDir, CustomShellType.Basic basicSetting, CustomShellType.MainCode mainCode, List<CustomShellType.FuncCode> funcCodeList) { XmlTextWriter xmlWriter = null; string filename = Path.Combine(basePathDir, shellTypeName); try { xmlWriter = new XmlTextWriter(filename, Encoding.UTF8); xmlWriter.Formatting = Formatting.Indented; xmlWriter.WriteStartDocument(); xmlWriter.WriteStartElement("customShellType"); { //BasicSetting xmlWriter.WriteStartElement("basicSetting"); { xmlWriter.WriteStartElement("name"); xmlWriter.WriteString(shellTypeName.Substring(0, shellTypeName.Length - 4)); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("serviceExample"); xmlWriter.WriteCData(basicSetting.ServiceExample); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("mainCodeParam"); { xmlWriter.WriteStartAttribute("location"); xmlWriter.WriteString(basicSetting.MainCodeParam.Location); xmlWriter.WriteEndAttribute(); xmlWriter.WriteStartAttribute("encrymode"); xmlWriter.WriteString(basicSetting.MainCodeParam.EncryMode.ToString()); xmlWriter.WriteEndAttribute(); xmlWriter.WriteString(basicSetting.MainCodeParam.Name); } xmlWriter.WriteEndElement(); } xmlWriter.WriteEndElement(); //MainCodeSetting xmlWriter.WriteStartElement("mainCodeSetting"); { xmlWriter.WriteStartElement("funcCodeParam"); { xmlWriter.WriteStartAttribute("location"); xmlWriter.WriteString(mainCode.FuncCodeParam.Location); xmlWriter.WriteEndAttribute(); xmlWriter.WriteStartAttribute("encrymode"); xmlWriter.WriteString(mainCode.FuncCodeParam.EncryMode.ToString()); xmlWriter.WriteEndAttribute(); xmlWriter.WriteString(mainCode.FuncCodeParam.Name); } xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("item"); xmlWriter.WriteCData(mainCode.Item); xmlWriter.WriteEndElement(); } xmlWriter.WriteEndElement(); //FuncCodeSetting xmlWriter.WriteStartElement("funcCodeSetting"); { foreach (CustomShellType.FuncCode func in funcCodeList) { xmlWriter.WriteStartElement("func"); { xmlWriter.WriteStartElement("name"); xmlWriter.WriteString(func.Name); xmlWriter.WriteEndElement(); foreach (CustomShellType.ParamStruct par in func.FuncParams) { xmlWriter.WriteStartElement("funcParameter"); { xmlWriter.WriteStartAttribute("location"); xmlWriter.WriteString(par.Location); xmlWriter.WriteEndAttribute(); xmlWriter.WriteStartAttribute("encrymode"); xmlWriter.WriteString(par.EncryMode.ToString()); xmlWriter.WriteEndAttribute(); xmlWriter.WriteString(par.Name); } xmlWriter.WriteEndElement(); } xmlWriter.WriteStartElement("item"); xmlWriter.WriteCData(func.Item); xmlWriter.WriteEndElement(); } xmlWriter.WriteEndElement(); } } xmlWriter.WriteEndElement(); } } catch (Exception ex) { throw new Exception(ex.Message); } finally { xmlWriter.Close(); } }
/// <summary> /// /// </summary> /// <param name="writer"></param> /// <param name="data"></param> public static void SerializeLLSDXmlElement(XmlTextWriter writer, OSD data) { switch (data.Type) { case OSDType.Unknown: writer.WriteStartElement(String.Empty, "undef", String.Empty); writer.WriteEndElement(); break; case OSDType.Boolean: writer.WriteStartElement(String.Empty, "boolean", String.Empty); writer.WriteString(data.AsString()); writer.WriteEndElement(); break; case OSDType.Integer: writer.WriteStartElement(String.Empty, "integer", String.Empty); writer.WriteString(data.AsString()); writer.WriteEndElement(); break; case OSDType.Real: writer.WriteStartElement(String.Empty, "real", String.Empty); writer.WriteString(data.AsString()); writer.WriteEndElement(); break; case OSDType.String: writer.WriteStartElement(String.Empty, "string", String.Empty); writer.WriteString(data.AsString()); writer.WriteEndElement(); break; case OSDType.Guid: writer.WriteStartElement(String.Empty, "Guid", String.Empty); writer.WriteString(data.AsString()); writer.WriteEndElement(); break; case OSDType.Date: writer.WriteStartElement(String.Empty, "date", String.Empty); writer.WriteString(data.AsString()); writer.WriteEndElement(); break; case OSDType.URI: writer.WriteStartElement(String.Empty, "uri", String.Empty); writer.WriteString(data.AsString()); writer.WriteEndElement(); break; case OSDType.Binary: writer.WriteStartElement(String.Empty, "binary", String.Empty); writer.WriteStartAttribute(String.Empty, "encoding", String.Empty); writer.WriteString("base64"); writer.WriteEndAttribute(); writer.WriteString(data.AsString()); writer.WriteEndElement(); break; case OSDType.Map: OSDMap map = (OSDMap)data; writer.WriteStartElement(String.Empty, "map", String.Empty); foreach (KeyValuePair<string, OSD> kvp in map) { writer.WriteStartElement(String.Empty, "key", String.Empty); writer.WriteString(kvp.Key); writer.WriteEndElement(); SerializeLLSDXmlElement(writer, kvp.Value); } writer.WriteEndElement(); break; case OSDType.Array: OSDArray array = (OSDArray)data; writer.WriteStartElement(String.Empty, "array", String.Empty); for (int i = 0; i < array.Count; i++) { SerializeLLSDXmlElement(writer, array[i]); } writer.WriteEndElement(); break; } }
/// <summary> /// Saves the data in this class to an XML file. /// </summary> public void SaveData() { XmlTextWriter writer = null; try { writer = new XmlTextWriter(File, Encoding.ASCII); writer.Indentation = 2; writer.Formatting = Formatting.Indented; writer.WriteStartElement("MentalisProxy"); // Write the version writer.WriteStartElement("Version"); writer.WriteStartAttribute("", "value", ""); writer.WriteString(Assembly.GetCallingAssembly().GetName().Version.ToString(2)); writer.WriteEndAttribute(); writer.WriteEndElement(); // Write the settings SaveSettings(writer); // Write the Authentication list to the file SaveUsers(writer); // Write the Listeners list to the file SaveListeners(writer); // Clean up writer.WriteEndElement(); } catch { } finally { if (writer != null) writer.Close(); } }
/// <summary> /// Save database properties. /// </summary> private void SaveProperties() { lock( SyncLock ) { //WATYF: //Added check for ".new" file, delete if exists. //Changed writer creation to include ".new" suffix on sFileProperties FileInfo fi = new FileInfo(sFileProperties + ".new"); if ( fi.Exists ){ fi.Delete();} XmlTextWriter writer = new XmlTextWriter(sFileProperties + ".new", null); writer.Formatting = Formatting.Indented; writer.Indentation=4; writer.WriteStartDocument(); writer.WriteComment("SharpHSQL Configuration"); writer.WriteProcessingInstruction("Instruction","Configuration Record"); writer.WriteStartElement("Properties",""); writer.WriteStartAttribute("LogFile",""); writer.WriteString(sFileScript); writer.WriteEndAttribute(); writer.WriteStartAttribute("DataFile",""); writer.WriteString(sFileCache); writer.WriteEndAttribute(); writer.WriteStartAttribute("Backup",""); writer.WriteString(sFileBackup); writer.WriteEndAttribute(); writer.WriteStartAttribute("Version",""); writer.WriteString(sVersion); writer.WriteEndAttribute(); writer.WriteStartAttribute("ReadOnly",""); if (bReadOnly == true) { writer.WriteString("true"); } else { writer.WriteString("false"); } writer.WriteEndAttribute(); writer.WriteStartAttribute("Modified",""); writer.WriteString(sModified); writer.WriteEndElement(); writer.WriteEndDocument(); writer.Flush(); writer.Close(); //WATYF: Added RenameNewToCurrent RenameNewToCurrent(sFileProperties); CloseProperties(); if (TracingHelper.TraceEnabled) TracingHelper.Write(); } }
/// <summary> /// Saves the settings in this class to an XML writer. /// </summary> /// <param name="writer">The XML writer to save the data to.</param> private void SaveSettings(XmlTextWriter writer) { writer.WriteStartElement("Settings"); string [] keys = new string[Settings.Count]; Settings.Keys.CopyTo(keys, 0); for (int i = 0; i < keys.Length; i++) { writer.WriteStartElement(keys[i]); writer.WriteStartAttribute("", "value", ""); writer.WriteString(Settings[keys[i]]); writer.WriteEndAttribute(); writer.WriteEndElement(); } writer.WriteEndElement(); }
public void SaveToFile(string text1) { XmlTextWriter writer = null; writer = new XmlTextWriter(text1, Encoding.Default); writer.Formatting = Formatting.Indented; writer.WriteStartDocument(); writer.WriteStartElement("root"); foreach (string str in this._objList) { writer.WriteStartElement("StringList"); writer.WriteStartAttribute("Value"); writer.WriteValue(str); writer.WriteEndAttribute(); writer.WriteEndElement(); } writer.WriteEndElement(); writer.Flush(); writer.Close(); }
/// <summary> /// Saves the authentication list to an XML writer. /// </summary> /// <param name="writer">The XML writer to save the users to.</param> private void SaveUsers(XmlTextWriter writer) { writer.WriteStartElement("Users"); string [] keys = UserList.Keys; string [] hashes = UserList.Hashes; for (int i = 0; i < keys.Length; i++) { writer.WriteStartElement(keys[i]); writer.WriteStartAttribute("", "value", ""); writer.WriteString(hashes[i]); writer.WriteEndAttribute(); writer.WriteEndElement(); } writer.WriteEndElement(); }