当前位置: 首页>>代码示例>>C#>>正文


C# System.Xml.XmlTextWriter.WriteEndAttribute方法代码示例

本文整理汇总了C#中System.Xml.XmlTextWriter.WriteEndAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# System.Xml.XmlTextWriter.WriteEndAttribute方法的具体用法?C# System.Xml.XmlTextWriter.WriteEndAttribute怎么用?C# System.Xml.XmlTextWriter.WriteEndAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Xml.XmlTextWriter的用法示例。


在下文中一共展示了System.Xml.XmlTextWriter.WriteEndAttribute方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SaveXmlDefaultConfigurationFile

        /// <summary>
        /// Create and Save a default configuration Xml file based on a easily specific or default defined xml string
        /// </summary>
        /// <param name="FilePath">The fullpath including filename.xml to save to</param>
        /// <param name="XmlConfigurationFileString">If not specified, then will use the XmlDefaultConfigurationFileString</param>
        /// <returns>True if succesfull created</returns>
        /// <remarks></remarks>
        public bool SaveXmlDefaultConfigurationFile(string FilePath, string XmlConfigurationFileString)
        {
            string theXmlString = ((XmlConfigurationFileString != null) ? XmlConfigurationFileString : XmlDefaultConfigurationFileString);
            //What Method You want to use ?, try any by simply change the var XmlSaveMethod declared at top
            switch (XmlSaveMethod) {
                case enumXmlSaveMethod.StreamWrite:
                    //Easy Method
                    using (System.IO.StreamWriter StreamWriter = new System.IO.StreamWriter(FilePath)) {
                        //Without Compact Framework more easily using file.WriteAllText but, CF doesn't have this method
                        StreamWriter.Write(theXmlString);
                        StreamWriter.Close();
                    }

                    return true;

                case enumXmlSaveMethod.XmlTextWriter:
                    //Alternative Method
                    using (System.Xml.XmlTextWriter XmlTextWriter = new System.Xml.XmlTextWriter(FilePath, System.Text.UTF8Encoding.UTF8)) {
                        XmlTextWriter.WriteStartDocument();
                        XmlTextWriter.WriteStartElement("configuration");
                        XmlTextWriter.WriteStartElement("appSettings");
                        foreach (string Item in GetListItems(theXmlString)) {
                            XmlTextWriter.WriteStartElement("add");

                            XmlTextWriter.WriteStartAttribute("key", string.Empty);
                            XmlTextWriter.WriteRaw(GetKey(Item));
                            XmlTextWriter.WriteEndAttribute();

                            XmlTextWriter.WriteStartAttribute("value", string.Empty);
                            XmlTextWriter.WriteRaw(GetValue(Item));
                            XmlTextWriter.WriteEndAttribute();

                            XmlTextWriter.WriteEndElement();

                        }

                        XmlTextWriter.WriteEndElement();
                        XmlTextWriter.WriteEndElement();
                        //XmlTextWriter.WriteEndDocument()
                        XmlTextWriter.Close();

                    }

                    return true;

                case enumXmlSaveMethod.XmlDocument:
                    //Method you will practice
                    System.Xml.XmlDocument XmlDoc = new System.Xml.XmlDocument();
                    System.Xml.XmlElement xRoot = XmlDoc.CreateElement("configuration");
                    XmlDoc.AppendChild(xRoot);
                    System.Xml.XmlElement xAppSettingsElement = XmlDoc.CreateElement("appSettings");
                    xRoot.AppendChild(xAppSettingsElement);

                    System.Xml.XmlElement xElement = default(System.Xml.XmlElement);
                    System.Xml.XmlAttribute xAttrKey = default(System.Xml.XmlAttribute);
                    System.Xml.XmlAttribute xAttrValue = default(System.Xml.XmlAttribute);
                    foreach (string Item in GetListItems(theXmlString)) {
                        xElement = XmlDoc.CreateElement("add");
                        xAttrKey = XmlDoc.CreateAttribute("key");
                        xAttrValue = XmlDoc.CreateAttribute("value");
                        xAttrKey.InnerText = GetKey(Item);
                        xElement.SetAttributeNode(xAttrKey);
                        xAttrValue.InnerText = GetValue(Item);
                        xElement.SetAttributeNode(xAttrValue);
                        xAppSettingsElement.AppendChild(xElement);
                    }

                    System.Xml.XmlProcessingInstruction XmlPI = XmlDoc.CreateProcessingInstruction("xml", "version='1.0' encoding='utf-8'");
                    XmlDoc.InsertBefore(XmlPI, XmlDoc.ChildNodes[0]);
                    XmlDoc.Save(FilePath);

                    return true;
            }
            return false;
        }
开发者ID:hjgode,项目名称:eMdiMail,代码行数:82,代码来源:AppSettings.cs


注:本文中的System.Xml.XmlTextWriter.WriteEndAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。