System.Xml.XmlDocument.CreateComment C# (CSharp) Method

CreateComment() public method

public CreateComment ( String data ) : XmlComment
data String
return XmlComment
        public virtual XmlComment CreateComment(String data)
        {
            return new XmlComment(data, this);
        }

Usage Example

        //////////////////////////////////////////////////////////////////////////
        public bool SaveToXmlFile(string Filename)
        {
            try
            {
                XmlDocument Doc = new XmlDocument();

                // header
                XmlDeclaration Decl = Doc.CreateXmlDeclaration("1.0", "utf-8", null);

                Assembly A = Assembly.GetExecutingAssembly();
                XmlComment Comment1 = Doc.CreateComment("Generated by: " + A.GetName());
                XmlComment Comment2 = Doc.CreateComment("Generated on: " + DateTime.Now.ToString());

                // root
                XmlNode RootNode = SaveToXmlNode(Doc);
                Doc.InsertBefore(Decl, Doc.DocumentElement);
                Doc.AppendChild(Comment1);
                Doc.AppendChild(Comment2);
                Doc.AppendChild(RootNode);

                // save to file
                XmlTextWriter Writer = new XmlTextWriter(Filename, null);
                Writer.Formatting = Formatting.Indented;
                Doc.Save(Writer);
                Writer.Close();

                return true;
            }
            catch
            {
                return false;
            }
        }
All Usage Examples Of System.Xml.XmlDocument::CreateComment