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


C# XmlDocument.CreateComment方法代码示例

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


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

示例1: SaveToXmlFile

        //////////////////////////////////////////////////////////////////////////
        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;
            }
        }
开发者ID:segafan,项目名称:wme1_jankavan_tlc_edition-repo,代码行数:34,代码来源:SettingsMgr.cs

示例2: buttonCreateNode_Click

        private void buttonCreateNode_Click(object sender, RoutedEventArgs e)
        {
            // Load the XML document.
              XmlDocument document = new XmlDocument();
              document.Load(@"C:\Beginning Visual C# 2012\Chapter 22\Books.xml");

              // Get the root element.
              XmlElement root = document.DocumentElement;

              // Create the new nodes.
              XmlElement newBook = document.CreateElement("book");
              XmlElement newTitle = document.CreateElement("title");
              XmlElement newAuthor = document.CreateElement("author");
              XmlElement newCode = document.CreateElement("code");
              XmlText title = document.CreateTextNode("Beginning Visual C# 2010");
              XmlText author = document.CreateTextNode("Karli Watson et al");
              XmlText code = document.CreateTextNode("1234567890");
              XmlComment comment = document.CreateComment("The previous edition");

              // Insert the elements.
              newBook.AppendChild(comment);
              newBook.AppendChild(newTitle);
              newBook.AppendChild(newAuthor);
              newBook.AppendChild(newCode);
              newTitle.AppendChild(title);
              newAuthor.AppendChild(author);
              newCode.AppendChild(code);
              root.InsertAfter(newBook, root.FirstChild);

              document.Save(@"C:\Beginning Visual C# 2012\Chapter 22\Books.xml");
        }
开发者ID:ktjones,项目名称:BVCS2012,代码行数:31,代码来源:MainWindow.xaml.cs

示例3: GetCapabilities

        /// <summary>
        /// Generates a capabilities file from a map object for use in WMS services
        /// </summary>
        /// <remarks>The capabilities document uses the v1.3.0 OpenGIS WMS specification</remarks>
        /// <param name="map">The map to create capabilities for</param>
        /// <param name="description">Additional description of WMS</param>
        /// <param name="request">An abstraction of the <see cref="HttpContext"/> request</param>
        /// <returns>Returns XmlDocument describing capabilities</returns>
        public static XmlDocument GetCapabilities(Map map, WmsServiceDescription description, IContextRequest request)
        {
            XmlDocument capabilities = new XmlDocument();

            // Insert XML tag
            capabilities.InsertBefore(capabilities.CreateXmlDeclaration("1.0", "UTF-8", String.Empty), capabilities.DocumentElement);
            string format = String.Format("Capabilities generated by SharpMap v. {0}", Assembly.GetExecutingAssembly().GetName().Version);
            capabilities.AppendChild(capabilities.CreateComment(format));

            // Create root node
            XmlNode rootNode = capabilities.CreateNode(XmlNodeType.Element, "WMS_Capabilities", WmsNamespaceUri);
            rootNode.Attributes.Append(CreateAttribute("version", "1.3.0", capabilities));

            XmlAttribute attr = capabilities.CreateAttribute("xmlns", "xsi", "http://www.w3.org/2000/xmlns/");
            attr.InnerText = "http://www.w3.org/2001/XMLSchema-instance";
            rootNode.Attributes.Append(attr);

            rootNode.Attributes.Append(CreateAttribute("xmlns:xlink", XlinkNamespaceUri, capabilities));
            XmlAttribute attr2 = capabilities.CreateAttribute("xsi", "schemaLocation",
                                                              "http://www.w3.org/2001/XMLSchema-instance");
            attr2.InnerText = "http://schemas.opengis.net/wms/1.3.0/capabilities_1_3_0.xsd";
            rootNode.Attributes.Append(attr2);

            // Build Service node
            rootNode.AppendChild(GenerateServiceNode(ref description, capabilities));

            // Build Capability node
            XmlNode capabilityNode = GenerateCapabilityNode(map, capabilities, description.PublicAccessURL, request);
            rootNode.AppendChild(capabilityNode);

            capabilities.AppendChild(rootNode);

            //TODO: Validate output against schema
            return capabilities;
        }
开发者ID:geobabbler,项目名称:SharpMap,代码行数:43,代码来源:ServerCapabilities.cs

示例4: WriteXml

        /// <summary>
        /// write layout data in xml-file for list of object
        /// </summary>
        /// <param name="fileName">name of xml-file</param>
        /// <param name="stores">list of object for writing layout data</param>
        public static void WriteXml(string fileName, IList<ILayoutDataStore> stores)
        {
            XmlDocument doc = new XmlDocument();
            XmlElement element;
            IList<ILayoutDataStore> controls = stores;
            // create a comment/pi and append
            if (controls == null) return;
            XmlNode node = doc.CreateComment(string.Format("Saved layout information for {0} controls of form", controls.Count));
            doc.AppendChild(node);
            node = doc.CreateElement(LayoutControlsElement);
            doc.AppendChild(node);

            foreach (ILayoutDataStore control in controls)
            {
                element = CreateElement(doc, ControlElement, NameElement, control.Name);
                node.AppendChild(element);
                element.AppendChild(CreateElement(doc, CheckElement, control.CheckCode));
                element.AppendChild(CreateCDataSection(doc, DataElement, control.Save()));
            }

            XmlTextWriter tw = new XmlTextWriter(FileUtils.MakeValidFilePath(fileName), null);
            tw.Formatting = Formatting.Indented;
            doc.Save(tw);
            tw.Close();
        }
开发者ID:vansickle,项目名称:dbexplorer,代码行数:30,代码来源:LayoutSettings.cs

示例5: GetReady

		public void GetReady ()
		{
			document = new XmlDocument ();
			document.NodeChanged += new XmlNodeChangedEventHandler (this.EventNodeChanged);
			document.NodeChanging += new XmlNodeChangedEventHandler (this.EventNodeChanging);
			comment = document.CreateComment ("foo");
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:7,代码来源:XmlCharacterDataTests.cs

示例6: button1_Click

        //Add a node
        private void button1_Click(object sender, EventArgs e)
        {
            //Load the XML document
            XmlDocument document = new XmlDocument();
            document.Load("../../Books.xml");

            //Get the root element
            XmlElement root = document.DocumentElement;


            //Create the new nodes
            XmlElement newBook = document.CreateElement("book");
            XmlElement newTitle = document.CreateElement("title");
            XmlElement newAuthor = document.CreateElement("author");
            XmlElement newCode = document.CreateElement("code");
            XmlText title = document.CreateTextNode("Beginning Visual C# 3rd Edition");  
            XmlText author = document.CreateTextNode("Karli Watson C# 3rd Edition");
            XmlText code = document.CreateTextNode("1234567890");
            XmlComment comment = document.CreateComment("This book is the book you are reading");

            //Insert the elements
            newBook.AppendChild(comment);
            newBook.AppendChild(newTitle);
            newBook.AppendChild(newAuthor);
            newBook.AppendChild(newCode);
            newTitle.AppendChild(title);
            newAuthor.AppendChild(author);
            newCode.AppendChild(code);
            root.InsertAfter(newBook, root.LastChild);

            document.Save("../../Books.xml");

            listBoxXmlNodes.Items.Clear();
            RecurseXmlDocument((XmlNode)document.DocumentElement, 0);  
        }
开发者ID:icegithub,项目名称:csharp-exercise,代码行数:36,代码来源:Form1.cs

示例7: Main

        static void Main(string[] args)
        {
            XmlDocument doc = new XmlDocument();
            XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", "UTF-8", "yes");
            doc.AppendChild(declaration);

            XmlComment comment = doc.CreateComment("my first xml document");
            doc.AppendChild(comment);

            XmlElement Employee = doc.CreateElement("Employee");
            doc.AppendChild(Employee);
            Employee.SetAttribute("ID", "48090");

            XmlElement Fname = doc.CreateElement("Fname");
            Fname.InnerXml = "naynish";
            Employee.AppendChild(Fname);

            XmlElement Lname = doc.CreateElement("Lname");
            Lname.InnerXml = "chaughule";
            Employee.AppendChild(Lname);

            XmlElement Salary = doc.CreateElement("Salary");
            Salary.InnerXml = "85000";
            Employee.AppendChild(Salary);

            doc.Save("FirstXml");
            Console.WriteLine("{0}", File.ReadAllText("FirstXml"));
            Console.WriteLine();
            SimpleXmlUsingLinq();
            Traverse();
            Update();
            Console.ReadLine();
        }
开发者ID:naynishchaughule,项目名称:CSharp,代码行数:33,代码来源:Program.cs

示例8: SerializeTypes

        public void SerializeTypes(IEnumerable<Type> types, TextWriter output) {
            var groupedByAssembly = from type in types
                                    group type by type.Module into groupedByModule
                                    group groupedByModule by groupedByModule.Key.Assembly;

            XmlDocument doc = new XmlDocument();
            doc.AppendChild(doc.CreateComment(MvcResources.TypeCache_DoNotModify));

            XmlElement typeCacheElement = doc.CreateElement("typeCache");
            doc.AppendChild(typeCacheElement);
            typeCacheElement.SetAttribute("lastModified", CurrentDate.ToString());
            typeCacheElement.SetAttribute("mvcVersionId", _mvcVersionId.ToString());

            foreach (var assemblyGroup in groupedByAssembly) {
                XmlElement assemblyElement = doc.CreateElement("assembly");
                typeCacheElement.AppendChild(assemblyElement);
                assemblyElement.SetAttribute("name", assemblyGroup.Key.FullName);

                foreach (var moduleGroup in assemblyGroup) {
                    XmlElement moduleElement = doc.CreateElement("module");
                    assemblyElement.AppendChild(moduleElement);
                    moduleElement.SetAttribute("versionId", moduleGroup.Key.ModuleVersionId.ToString());

                    foreach (Type type in moduleGroup) {
                        XmlElement typeElement = doc.CreateElement("type");
                        moduleElement.AppendChild(typeElement);
                        typeElement.AppendChild(doc.CreateTextNode(type.FullName));
                    }
                }
            }

            doc.Save(output);
        }
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:33,代码来源:TypeCacheSerializer.cs

示例9: Save

        public bool Save(string path)
        {
            bool saved = true;
            XmlDocument m_Xdoc = new XmlDocument();
            try
            {
                m_Xdoc.RemoveAll();

                XmlNode node = m_Xdoc.CreateXmlDeclaration("1.0", "utf-8", string.Empty);
                m_Xdoc.AppendChild(node);

                node = m_Xdoc.CreateComment($" Profile Configuration Data. {DateTime.Now} ");
                m_Xdoc.AppendChild(node);

                node = m_Xdoc.CreateWhitespace("\r\n");
                m_Xdoc.AppendChild(node);

                node = m_Xdoc.CreateNode(XmlNodeType.Element, "Profile", null);

                m_Xdoc.AppendChild(node);

                m_Xdoc.Save(path);
            }
            catch
            {
                saved = false;
            }

            return saved;
        }
开发者ID:SonicFreak94,项目名称:DS4Windows,代码行数:30,代码来源:SaveWhere.cs

示例10: Perform

        /// <summary>
        /// XML Documentに変換。
        /// </summary>
        /// <param name="xmlText"></param>
        /// <returns></returns>
        public XmlDocument Perform(
            MemoryGloballistconfig moGlcnf,
            Log_Reports log_Reports
            )
        {
            XmlDocument doc = new XmlDocument();

            XmlElement rootElm = doc.CreateElement("global-list-config");
            doc.AppendChild(rootElm);

            rootElm.AppendChild(doc.CreateComment(" 変数の型名を、グローバルリストに並んでいる順番に並べてください "));

            // 変数の型名の追加
            foreach (GloballistconfigTypesection typeSection in moGlcnf.TypesectionList.List_Item)
            {
                XmlElement typeElm = doc.CreateElement("type");
                typeElm.SetAttribute(SrsAttrName.S_NAME, typeSection.Name_Type);
                rootElm.AppendChild(typeElm);
            }

            rootElm.AppendChild(doc.CreateComment(" 担当者の情報を記述してください。担当者名、変数の型名、変数番号のそれぞれ、順不同です。 "));
            // 担当者情報の追加
            foreach (GloballistconfigHuman human in moGlcnf.Dictionary_Human.Values)
            {
                XmlElement humanElm = doc.CreateElement("human");
                humanElm.SetAttribute(SrsAttrName.S_NAME, human.Name);
                rootElm.AppendChild(humanElm);

                // 担当変数の型の情報の追加
                foreach (GloballistconfigVariable var in human.Dictionary_Variable.Values)
                {
                    XmlElement varElm = doc.CreateElement("variable");
                    varElm.SetAttribute("type", var.Name_Type);
                    humanElm.AppendChild(varElm);

                    // 担当変数の情報の追加
                    foreach (GloballistconfigNumber num in var.Dictionary_Number.Values)
                    {
                        XmlElement numElm = doc.CreateElement("number");
                        numElm.SetAttribute("range", num.Text_Range);
                        numElm.SetAttribute("priority", num.Priority.Text);
                        varElm.AppendChild(numElm);
                    }
                }
            }
            return doc;
        }
开发者ID:muzudho,项目名称:CSVExE,代码行数:52,代码来源:GloballistAction00003.cs

示例11: XMLDocInstance

 public XMLDocInstance(ObjectInstance prototype, string path)
     : this(prototype)
 {
     _doc = new XmlDocument();
     _path = path;
     _doc.AppendChild(_doc.CreateXmlDeclaration("1.0", null, null));
     _doc.AppendChild(_doc.CreateComment("Generated by Sphere SFML XML Content Serializer v1.0"));
 }
开发者ID:Radnen,项目名称:sphere-sfml,代码行数:8,代码来源:XMLDocConstructor.cs

示例12: CreateEmptyComment

        public static void CreateEmptyComment()
        {
            var xmlDocument = new XmlDocument();
            var comment = xmlDocument.CreateComment(String.Empty);

            Assert.Equal("<!---->", comment.OuterXml);
            Assert.Equal(String.Empty, comment.InnerText);
            Assert.Equal(comment.NodeType, XmlNodeType.Comment);
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:9,代码来源:CreateCommentTests.cs

示例13: Save

        public static void Save()
        {
            string filepath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;

            string FileName = Path.Combine(filepath, "Options.xml");

            XmlDocument dom = new XmlDocument();
            XmlDeclaration decl = dom.CreateXmlDeclaration("1.0", "utf-8", null);
            dom.AppendChild(decl);
            XmlElement sr = dom.CreateElement("Options");

            XmlComment comment = dom.CreateComment("LogPath is the default path to check for log files when you press the Parse Button");
            sr.AppendChild(comment);
            XmlElement elem = dom.CreateElement("LogPath");
            elem.InnerText = Program.opt.DefaultLogPath.ToString();
            sr.AppendChild(elem);

            comment = dom.CreateComment("OutputPath is the default path to use when you press the Save Button after parsing");
            sr.AppendChild(comment);
            elem = dom.CreateElement("OutputPath");
            elem.InnerText = Program.opt.DefaultOutputPath.ToString();
            sr.AppendChild(elem);

            comment = dom.CreateComment("POLPath is the default path to use for the POL Parsing Tools in the Tools Menu");
            sr.AppendChild(comment);
            elem = dom.CreateElement("POLPath");
            elem.InnerText = Program.opt.DefaultPOLPath.ToString();
            sr.AppendChild(elem);

            comment = dom.CreateComment("LastUsedList is the last Keyword List used when Options was last saved");
            sr.AppendChild(comment);
            elem = dom.CreateElement("LastUsedList");
            elem.InnerText = Program.Keys.CurrentList.ToString();
            sr.AppendChild(elem);

            comment = dom.CreateComment("Case decides if to use Case Sensitive searches based on Keywords in the main Parser");
            sr.AppendChild(comment);
            elem = dom.CreateElement("Case");
            elem.InnerText = Program.opt.CaseParse.ToString();
            sr.AppendChild(elem);

            dom.AppendChild(sr);
            dom.Save(FileName);
        }
开发者ID:polserver,项目名称:poltools,代码行数:44,代码来源:Options.cs

示例14: ToXml

        public static XmlDocument ToXml(this OrganizationSnapshot[] matrix)
        {
            var document = new XmlDocument();

            document.AppendChild(document.CreateXmlDeclaration("1.0", "UTF-8", "yes"));
            document.AppendChild(document.CreateComment("Comparison matrix"));

            var root = document.CreateElement("matrix");
            document.AppendChild(root);

            XmlElement element;
            XmlAttribute attribute;

            var solutions = document.CreateElement(Constants.Xml.SOLUTIONS);
            root.AppendChild(solutions);

            foreach (var solution in matrix[0].Solutions)
            {
                element = document.CreateElement(Constants.Xml.SOLUTION);

                attribute = document.CreateAttribute(Constants.Xml.UNIQUE_NAME);
                attribute.Value = solution.UniqueName;
                element.Attributes.Append(attribute);

                attribute = document.CreateAttribute(Constants.Xml.FRIENDLY_NAME);
                attribute.Value = solution.FriendlyName;
                element.Attributes.Append(attribute);

                attribute = document.CreateAttribute(Constants.Xml.VERSION);
                attribute.Value = solution.Version.ToString();
                element.Attributes.Append(attribute);

                solutions.AppendChild(element);
            }

            var assemblies = document.CreateElement(Constants.Xml.ASSEMBLIES);
            root.AppendChild(assemblies);

            foreach (var assembly in matrix[0].Assemblies)
            {
                element = document.CreateElement(Constants.Xml.ASSEMBLY);

                attribute = document.CreateAttribute(Constants.Xml.FRIENDLY_NAME);
                attribute.Value = assembly.FriendlyName;
                element.Attributes.Append(attribute);

                attribute = document.CreateAttribute(Constants.Xml.VERSION);
                attribute.Value = assembly.Version.ToString();
                element.Attributes.Append(attribute);

                assemblies.AppendChild(element);
            }

            return document;
        }
开发者ID:rajyraman,项目名称:XrmToolBox.Plugins,代码行数:55,代码来源:Extensions.cs

示例15: CreateEmptyResourceFile

        public static void CreateEmptyResourceFile(string path)
        {
            XmlDocument document = new XmlDocument();
            XmlElement root = document.CreateElement("Resources");
            XmlComment comment = document.CreateComment("Here you can define resources used by Speech Sequencer");

            root.AppendChild(comment);
            document.AppendChild(root);
            document.DocumentElement.SetAttribute("xmlns:var", VariableNamespace);

            document.Save(path);
        }
开发者ID:3DI70R,项目名称:SpeechSequencerCore,代码行数:12,代码来源:ResourceManager.cs


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