System.Xml.XmlTextWriter.WriteComment C# (CSharp) Method

WriteComment() public method

public WriteComment ( string text ) : void
text string
return void
        public override void WriteComment(string text) {
            try {
                if (null != text && (text.IndexOf("--", StringComparison.Ordinal)>=0 || (text.Length != 0 && text[text.Length-1] == '-'))) {
                    throw new ArgumentException(Res.GetString(Res.Xml_InvalidCommentChars));
                }
                AutoComplete(Token.Comment);
                textWriter.Write("<!--");
                if (null != text) {
                    xmlEncoder.WriteRawWithSurrogateChecking(text);
                }
                textWriter.Write("-->");
            }
            catch {
                currentState = State.Error;
                throw;
            }
        }

Usage Example

Example #1
0
        /// <summary>
        /// 写入配置参数数据
        /// </summary>
        /// <param name="Path"></param>
        public void WriterXml(string Path)
        {


            try
            {
                // 创建XmlTextWriter类的实例对象
                XmlTextWriter textWriter = new XmlTextWriter(Path, null);
                textWriter.Formatting = Formatting.Indented;

                // 开始写过程,调用WriteStartDocument方法
                textWriter.WriteStartDocument();

                // 写入说明
                textWriter.WriteComment("First Comment XmlTextWriter Sample Example");
                textWriter.WriteComment("w3sky.xml in root dir");

                //创建一个节点
                textWriter.WriteStartElement("Administrator");
                textWriter.WriteElementString("Name", "formble");
                textWriter.WriteElementString("site", "w3sky.com");
                textWriter.WriteEndElement();

                // 写文档结束,调用WriteEndDocument方法
                textWriter.WriteEndDocument();

                // 关闭textWriter
                textWriter.Close();

            }
            catch (System.Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
All Usage Examples Of System.Xml.XmlTextWriter::WriteComment