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


C# XmlTextWriter.WriteStartElement方法代码示例

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


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

示例1: WriteXMLDocument

        private static void WriteXMLDocument(List<List<Review>> allResults)
        {
            string fileName = "../../reviews-search-results.xml";
            Encoding encoding = Encoding.GetEncoding("UTF-8");


            using (XmlTextWriter writer = new XmlTextWriter(fileName, encoding))
            {
                writer.Formatting = Formatting.Indented;
                writer.IndentChar = '\t';
                writer.Indentation = 1;

                writer.WriteStartDocument();

                writer.WriteStartElement("search-results");

                foreach (var results in allResults)
                {
                    writer.WriteStartElement("result-set");
                    var orderedResult = (from e in results
                                         orderby e.DateOfCreation
                                         select e).ToList();

                    WriteBookInXML(orderedResult, writer);
                    writer.WriteEndElement();
                }
                writer.WriteEndDocument();
            }
        }
开发者ID:nnaidenov,项目名称:TelerikAcademy,代码行数:29,代码来源:ReviewsSearcher.cs

示例2: button1_Click

 // XmlWriterSample1/form.cs
 private void button1_Click(object sender, System.EventArgs e)
 {
     // change to match you path structure
     string fileName="booknew.xml";
     //create the XmlTextWriter
     XmlTextWriter tw=new XmlTextWriter(fileName,null);
     //set the formatting to indented
     tw.Formatting=Formatting.Indented;
     tw.WriteStartDocument();
     //Start creating elements and attributes
     tw.WriteStartElement("book");
     tw.WriteAttributeString("genre","Mystery");
     tw.WriteAttributeString("publicationdate","2001");
     tw.WriteAttributeString("ISBN","123456789");
     tw.WriteElementString("title","Case of the Missing Cookie");
     tw.WriteStartElement("author");
     tw.WriteElementString("name","Cookie Monster");
     tw.WriteEndElement();
     tw.WriteElementString("price","9.99");
     tw.WriteEndElement();
     tw.WriteEndDocument();
     //clean up
     tw.Flush();
     tw.Close();
 }
开发者ID:alannet,项目名称:example,代码行数:26,代码来源:XmlWriterSample1.cs

示例3: CreateConfig

        private void CreateConfig()
        {
            this.ConfigFileLocation = Path.Combine(this.ThemeDirectory, "Theme.config");

            using (var xml = new XmlTextWriter(this.ConfigFileLocation, Encoding.UTF8))
            {
                xml.WriteStartDocument(true);
                xml.Formatting = Formatting.Indented;
                xml.Indentation = 4;

                xml.WriteStartElement("configuration");
                xml.WriteStartElement("appSettings");

                this.AddKey(xml, "ThemeName", this.Info.ThemeName);
                this.AddKey(xml, "Author", this.Info.Author);
                this.AddKey(xml, "AuthorUrl", this.Info.AuthorUrl);
                this.AddKey(xml, "AuthorEmail", this.Info.AuthorEmail);
                this.AddKey(xml, "ConvertedBy", this.Info.ConvertedBy);
                this.AddKey(xml, "ReleasedOn", this.Info.ReleasedOn);
                this.AddKey(xml, "Version", this.Info.Version);
                this.AddKey(xml, "Category", this.Info.Category);
                this.AddKey(xml, "Responsive", this.Info.Responsive ? "Yes" : "No");
                this.AddKey(xml, "Framework", this.Info.Framework);
                this.AddKey(xml, "Tags", string.Join(",", this.Info.Tags));
                this.AddKey(xml, "HomepageLayout", this.Info.HomepageLayout);
                this.AddKey(xml, "DefaultLayout", this.Info.DefaultLayout);

                xml.WriteEndElement(); //appSettings
                xml.WriteEndElement(); //configuration
                xml.Close();
            }
        }
开发者ID:frapid,项目名称:frapid,代码行数:32,代码来源:ThemeCreator.cs

示例4: SaveRegister

        private bool SaveRegister(string RegisterKey)
        {
            try
            {
                
                Encryption enc = new Encryption();
                FileStream fs = new FileStream("reqlkd.dll", FileMode.Create);
                XmlTextWriter w = new XmlTextWriter(fs, Encoding.UTF8);

                // Khởi động tài liệu.
                w.WriteStartDocument();
                w.WriteStartElement("QLCV");

                // Ghi một product.
                w.WriteStartElement("Register");
                w.WriteAttributeString("GuiNumber", enc.EncryptData(sGuiID));
                w.WriteAttributeString("Serialnumber", enc.EncryptData(sSerial));
                w.WriteAttributeString("KeyRegister", enc.EncryptData(RegisterKey, sSerial + sGuiID));
                w.WriteEndElement();

                // Kết thúc tài liệu.
                w.WriteEndElement();
                w.WriteEndDocument();
                w.Flush();
                w.Close();
                fs.Close();
                return true;
            }
            catch (Exception ex)
            {

                return false;
            }
        }
开发者ID:phinq19,项目名称:qlcongviec,代码行数:34,代码来源:frmRegister.cs

示例5: Serialize

        public static string Serialize(IEnumerable<MicroDataEntry> entries)
        {
            StringBuilder sb = new StringBuilder(3000);
            using (StringWriter sw = new StringWriter(sb))
            {
                using (XmlTextWriter xw = new XmlTextWriter(sw))
                {
                    xw.WriteStartElement("microData");

                    foreach (MicroDataEntry microDataEntry in entries)
                    {
                        xw.WriteStartElement("entry");

                        if (microDataEntry.ContentType.HasValue)
                        {
                            xw.WriteAttributeString("contentType", microDataEntry.ContentType.Value.ToString());
                        }

                        xw.WriteAttributeString("entryType", microDataEntry.Type.ToString());
                        xw.WriteAttributeString("selector", microDataEntry.Selector);
                        xw.WriteAttributeString("value", microDataEntry.Value);

                        xw.WriteEndElement();
                    }

                    xw.WriteEndElement();
                }
            }

            return sb.ToString();
        }
开发者ID:4-Roads,项目名称:FourRoads.TelligentCommunity,代码行数:31,代码来源:MicroDataSerializer.cs

示例6: updateCartFile

        public void updateCartFile(List<CartObject> newCartObj)
        {
            bool found = false;

            string cartFile = "C:\\Users\\Kiran\\Desktop\\cart.xml";

            if (!File.Exists(cartFile))
            {
                XmlTextWriter xWriter = new XmlTextWriter(cartFile, Encoding.UTF8);
                xWriter.Formatting = Formatting.Indented;
                xWriter.WriteStartElement("carts");
                xWriter.WriteStartElement("cart");
                xWriter.WriteAttributeString("emailId", Session["emailId"].ToString());
                xWriter.Close();
            }

            XmlDocument doc = new XmlDocument();
            doc.Load(cartFile);
            foreach (CartObject cartItem in newCartObj)
            {
                foreach (XmlNode xNode in doc.SelectNodes("carts"))
                {
                    XmlNode cartNode = xNode.SelectSingleNode("cart");
                    if (cartNode.Attributes["emailId"].InnerText == Session["emailId"].ToString())
                    {
                        found = true;
                        XmlNode bookNode = doc.CreateElement("book");
                        XmlNode nameNode = doc.CreateElement("name");
                        nameNode.InnerText = cartItem.itemName;
                        XmlNode priceNode = doc.CreateElement("price");
                        priceNode.InnerText = cartItem.itemPrice.ToString();
                        XmlNode quantityNode = doc.CreateElement("quantity");
                        quantityNode.InnerText = "1";
                        bookNode.AppendChild(nameNode);
                        bookNode.AppendChild(priceNode);
                        bookNode.AppendChild(quantityNode);
                        cartNode.AppendChild(bookNode);
                    }
                }
                if(!found)
                  {
                        XmlNode cartNode = doc.CreateElement("cart");
                        cartNode.Attributes["emailId"].InnerText = Session["emailId"].ToString();
                        XmlNode bookNode = doc.CreateElement("book");
                        XmlNode nameNode = doc.CreateElement("name");
                        nameNode.InnerText = cartItem.itemName;
                        XmlNode priceNode = doc.CreateElement("price");
                        priceNode.InnerText = cartItem.itemPrice.ToString();
                        XmlNode quantityNode = doc.CreateElement("quantity");
                        quantityNode.InnerText = "1";
                        bookNode.AppendChild(nameNode);
                        bookNode.AppendChild(priceNode);
                        bookNode.AppendChild(quantityNode);
                        cartNode.AppendChild(bookNode);
                        doc.DocumentElement.AppendChild(cartNode);

                  }
                }
            doc.Save(cartFile);
        }
开发者ID:kiranprakash154,项目名称:SellingBooks,代码行数:60,代码来源:WelcomePage.aspx.cs

示例7: Save

        public static void Save(VProject vProject, XmlTextWriter xml)
        {
            Debug.Assert(vProject.ProjectDescriptor != null);
            Debug.Assert(vProject.ProjectDescriptor.Code != null);
            Debug.Assert(vProject.Items != null);

            xml.WriteStartElement("Code");
            xml.WriteValue(vProject.ProjectDescriptor.Code);
            xml.WriteEndElement();

            xml.WriteStartElement("ProjectItems");
            foreach (var item in vProject.Items)
            {
                xml.WriteStartElement("ProjectItem");

                xml.WriteStartElement("DisplayName");
                xml.WriteValue(item.DisplayName);
                xml.WriteEndElement();

                xml.WriteStartElement("Code");
                xml.WriteValue(item.Descriptor.Code);
                xml.WriteEndElement();

                xml.WriteEndElement();
            }
            xml.WriteEndElement();
        }
开发者ID:mohsenboojari,项目名称:offwind,代码行数:27,代码来源:ProjectHandler.cs

示例8: Export

        /// <summary>
        /// Export a MacGui style plist preset.
        /// </summary>
        /// <param name="path">
        /// The path.
        /// </param>
        /// <param name="preset">
        /// The preset.
        /// </param>
        /// <param name="build">
        /// The build.PictureModulusPictureModulus
        /// </param>
        public static void Export(string path, Preset preset, string build)
        {
            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            EncodeTask parsed = new EncodeTask(preset.Task);
            using (XmlTextWriter xmlWriter = new XmlTextWriter(path, Encoding.UTF8) { Formatting = Formatting.Indented })
            {
                // Header
                xmlWriter.WriteStartDocument();
                xmlWriter.WriteDocType(
                    "plist", "-//Apple//DTD PLIST 1.0//EN", @"http://www.apple.com/DTDs/PropertyList-1.0.dtd", null);

                xmlWriter.WriteStartElement("plist");
                xmlWriter.WriteStartElement("array");

                // Add New Preset Here. Can write multiple presets here if required in future.
                WritePreset(xmlWriter, parsed, preset, build);

                // Footer
                xmlWriter.WriteEndElement();
                xmlWriter.WriteEndElement();

                xmlWriter.WriteEndDocument();

                // Closeout
                xmlWriter.Close();
            }
        }
开发者ID:JuannyWang,项目名称:HandBrake-QuickSync-Mac,代码行数:43,代码来源:PlistUtility.cs

示例9: Main

        public static void Main()
        {
            using (XmlTextWriter writer = new XmlTextWriter("../../albums.xml", Encoding.UTF8))
            {
                writer.Formatting = Formatting.Indented;
                writer.IndentChar = '\t';
                writer.Indentation = 1;

                writer.WriteStartDocument();
                writer.WriteStartElement("albums");

                using (XmlTextReader reader = new XmlTextReader("../../catalog.xml"))
                {
                    while (reader.Read())
                    {
                        if (reader.NodeType == XmlNodeType.Element)
                        {
                            if (reader.Name == "name")
                            {
                                writer.WriteStartElement("album");
                                writer.WriteElementString("name", reader.ReadElementString());
                            }

                            if (reader.Name == "artist")
                            {
                                writer.WriteElementString("artist", reader.ReadElementString());
                                writer.WriteEndElement();
                            }
                        }
                    }
                }

                writer.WriteEndDocument();
            }
        }
开发者ID:MarinaGeorgieva,项目名称:TelerikAcademy,代码行数:35,代码来源:Program.cs

示例10: Export

        /// <summary>
        /// Export a MacGui style plist preset.
        /// </summary>
        /// <param name="path">
        /// The path.
        /// </param>
        /// <param name="preset">
        /// The preset.
        /// </param>
        public static void Export(string path, Preset preset)
        {
            EncodeTask parsed = QueryParserUtility.Parse(preset.Query);
            XmlTextWriter xmlWriter = new XmlTextWriter(path, Encoding.UTF8) { Formatting = Formatting.Indented };

            // Header
            xmlWriter.WriteStartDocument();
            xmlWriter.WriteDocType("plist", "-//Apple//DTD PLIST 1.0//EN",
                                @"http://www.apple.com/DTDs/PropertyList-1.0.dtd", null);

            xmlWriter.WriteStartElement("plist");
            xmlWriter.WriteStartElement("array");

            // Add New Preset Here. Can write multiple presets here if required in future.
            WritePreset(xmlWriter, parsed, preset);

            // Footer
            xmlWriter.WriteEndElement();
            xmlWriter.WriteEndElement();

            xmlWriter.WriteEndDocument();

            // Closeout
            xmlWriter.Close();
        }
开发者ID:shkolnik,项目名称:HandBrake,代码行数:34,代码来源:PlistUtility.cs

示例11: ConvetTextToXml

        public static void ConvetTextToXml()
        {
            string[] lines;
            const int NumberOfTagsForEachPerson = 3;
            using (var writer = new XmlTextWriter("../../toXml.xml", Encoding.UTF8))
            {
                writer.Formatting = Formatting.Indented;
                writer.IndentChar = '\t';
                writer.Indentation = 1;

                using (StreamReader reader = new StreamReader("../../fromText.txt"))
                {
                    lines = reader.ReadToEnd().Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);

                    writer.WriteStartDocument();
                    writer.WriteStartElement("Persons");

                    for (int i = 0; i < lines.Length; i += NumberOfTagsForEachPerson)
                    {
                        writer.WriteStartElement("Person");
                        writer.WriteElementString("name", lines[i]);
                        writer.WriteElementString("adress", lines[i + 1]);
                        writer.WriteElementString("telephone", lines[i + 2]);
                        writer.WriteEndElement();
                    }

                    writer.WriteEndElement();
                }
            }

            Console.WriteLine("\tDONE!!! Check file!");
        }
开发者ID:EmilMitev,项目名称:Telerik-Academy,代码行数:32,代码来源:Task07.cs

示例12: CreateXml

 public static void CreateXml(string path)
 {
     XmlTextWriter writer = new XmlTextWriter(path, Encoding.UTF8) {
         Formatting = Formatting.Indented
     };
     writer.WriteStartDocument();
     writer.WriteStartElement("root");
     for (int i = 0; i < 5; i++)
     {
         writer.WriteStartElement("Node");
         writer.WriteAttributeString("Text", "这是文章内容!~!!~~");
         writer.WriteAttributeString("ImageUrl", "");
         writer.WriteAttributeString("NavigateUrl", "Url..." + i.ToString());
         writer.WriteAttributeString("Expand", "true");
         for (int j = 0; j < 5; j++)
         {
             writer.WriteStartElement("Node");
             writer.WriteAttributeString("Text", "......名称");
             writer.WriteAttributeString("NavigateUrl", "Url..." + i.ToString());
             writer.WriteEndElement();
         }
         writer.WriteEndElement();
     }
     writer.WriteFullEndElement();
     writer.Close();
 }
开发者ID:xiluo,项目名称:document-management,代码行数:26,代码来源:XmlUtil.cs

示例13: Main

        static void Main(string[] args)
        {
            using (XmlTextWriter writer = new XmlTextWriter(OutputPath, Encoding.UTF8))
            {
                writer.Formatting = Formatting.Indented;
                writer.Indentation = 4;
                writer.IndentChar = ' ';
                writer.WriteStartDocument();
                writer.WriteStartElement("albums");

                using (XmlReader reader = XmlReader.Create(InputPath))
                {
                    while (reader.Read())
                    {
                        if (reader.NodeType == XmlNodeType.Element)
                        {
                            if (reader.Name == "name")
                            {
                                writer.WriteStartElement("album");
                                writer.WriteElementString("name", reader.ReadElementString());
                            }
                            else if (reader.Name == "artist")
                            {
                                writer.WriteElementString("artist", reader.ReadElementString());
                                writer.WriteEndElement();
                            }
                        }
                    }
                }

                writer.WriteEndDocument();
            }

            Console.WriteLine("Parsing is finished. Your document is ready.");
        }
开发者ID:InKolev,项目名称:TelerikAcademy,代码行数:35,代码来源:CatalogueToAlbums.cs

示例14: TraverseDirectory

        /// <summary>
        /// The traverse directory.
        /// </summary>
        /// <param name="directory">
        /// The directory.
        /// </param>
        public static void TraverseDirectory(string directory)
        {
            // Write a program to traverse given directory and write to a XML file its contents together with all subdirectories and files.
            var dir = new DirectoryInfo(directory);

            using (writer = new XmlTextWriter(xmlDirFilename, Encoding.UTF8))
            {
                writer.Formatting = Formatting.Indented;
                writer.IndentChar = '\t';
                writer.Indentation = 1;

                writer.WriteStartDocument();
                writer.WriteStartElement("dirStructure");

                foreach (var file in dir.GetFiles())
                {
                    writer.WriteStartElement("file");
                    writer.WriteAttributeString("name", file.Name);
                    writer.WriteEndElement();
                }

                foreach (var subDir in dir.GetDirectories())
                {
                    CreateSubdirectoryXml(subDir);
                }

                writer.WriteEndDocument();
            }
        }
开发者ID:atanas-georgiev,项目名称:Databases-Homeworks,代码行数:35,代码来源:Task9.cs

示例15: SaveManToXml

        private static void SaveManToXml(IList<Man> people)
        {
            string fileName = "../../peoples.xml";

            using (XmlTextWriter writer = new XmlTextWriter(fileName, Encoding.GetEncoding("windows-1251")))
            {
                writer.Formatting = Formatting.Indented;
                writer.IndentChar = '\t';
                writer.Indentation = 1;

                writer.WriteStartDocument();

                writer.WriteStartElement("people");

                foreach (var man in people)
                {
                    writer.WriteStartElement("person");
                    writer.WriteElementString("name", man.Name);
                    writer.WriteElementString("address", man.Address);
                    writer.WriteElementString("phone", man.Phone);
                    writer.WriteEndElement();
                }

                writer.WriteEndElement();
            }
        }
开发者ID:NikolayKostadinov,项目名称:Homeworks,代码行数:26,代码来源:CreateXmlFromTextFile.cs


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