當前位置: 首頁>>代碼示例>>C#>>正文


C# XmlTextWriter.WriteStartDocument方法代碼示例

本文整理匯總了C#中System.Xml.XmlTextWriter.WriteStartDocument方法的典型用法代碼示例。如果您正苦於以下問題:C# XmlTextWriter.WriteStartDocument方法的具體用法?C# XmlTextWriter.WriteStartDocument怎麽用?C# XmlTextWriter.WriteStartDocument使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Xml.XmlTextWriter的用法示例。


在下文中一共展示了XmlTextWriter.WriteStartDocument方法的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: Main

        static void Main(string[] args)
        {
            string textFile = "../../PersonData.txt";
            string xmlFile = "../../Person.xml";

            using (XmlTextWriter xmlWriter = new XmlTextWriter(xmlFile, Encoding.GetEncoding("utf-8")))
            {
                xmlWriter.Formatting = Formatting.Indented;
                xmlWriter.IndentChar = '\t';
                xmlWriter.Indentation = 1;

                xmlWriter.WriteStartDocument();
                xmlWriter.WriteStartElement("person");
                xmlWriter.WriteAttributeString("id", "1");

                using (StreamReader fileReader = new StreamReader(textFile))
                {
                    string name = fileReader.ReadLine();
                    xmlWriter.WriteElementString("name", name);
                    string address = fileReader.ReadLine();
                    xmlWriter.WriteElementString("address", address);
                    string phone = fileReader.ReadLine();
                    xmlWriter.WriteElementString("phone", phone);
                }

                xmlWriter.WriteEndElement();
                xmlWriter.WriteEndDocument();
            }
        }
開發者ID:DimitarDKirov,項目名稱:Data-Bases,代碼行數:29,代碼來源:Program.cs

示例4: Main

        public static void Main()
        {
            using (XmlTextWriter writer = new XmlTextWriter(DirPath, Encoding.UTF8))
            {
                writer.Formatting = Formatting.Indented;
                writer.IndentChar = ' ';
                writer.Indentation = 2;

                string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                writer.WriteStartDocument();
                writer.WriteStartElement("directories");

                try
                {
                    TraverseDirectory(desktopPath, writer);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Console.WriteLine("Change the desktopPath.");
                }

                writer.WriteEndDocument();
            }

            Console.WriteLine("Xml document successfully created.");
        }
開發者ID:AYankova,項目名稱:Databases,代碼行數:27,代碼來源:Program.cs

示例5: 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

示例6: 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

示例7: InitWriter

		/// <summary>
		/// Initializes the writer to write redirected output. 
		/// </summary>              
		/// <remarks>Depending on the <c>method</c> attribute value, 
		/// <c>XmlTextWriter</c> or <c>StreamWriter</c> is created. 
		/// <c>XmlTextWriter</c> is used for outputting XML and  
		/// <c>StreamWriter</c> - for plain text.
		/// </remarks>
		public void InitWriter(XmlResolver outResolver)
		{
			if (outResolver == null)
			{
				outResolver = new OutputResolver(Directory.GetCurrentDirectory());
			}
			// Save current directory
			//storedDir = Directory.GetCurrentDirectory();
			string outFile = outResolver.ResolveUri(null, href).LocalPath;
			DirectoryInfo dir = Directory.GetParent(outFile);
			if (!dir.Exists)
				dir.Create();
			// Create writer
			if (method == OutputMethod.Xml)
			{
				xmlWriter = new XmlTextWriter(outFile, encoding);
				if (indent)
					xmlWriter.Formatting = Formatting.Indented;
				if (!omitXmlDecl)
				{
					if (standalone)
						xmlWriter.WriteStartDocument(true);
					else
						xmlWriter.WriteStartDocument();
				}
			}
			else
				textWriter = new StreamWriter(outFile, false, encoding);
			// Set new current directory            
			//Directory.SetCurrentDirectory(dir.ToString());                                    
            href = ""; // clean the href for the next usage
		}
開發者ID:zanyants,項目名稱:mvp.xml,代碼行數:40,代碼來源:OutputState.cs

示例8: 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

示例9: createXML

        public void createXML(string XmlFilePath, StringBuilder str)
        {
            //   XmlFilePath = this.XmlFilePath;
            try
            {
                if (!File.Exists(XmlFilePath))
                {
                    XmlTextWriter textWritter = new XmlTextWriter(XmlFilePath, Encoding.UTF8);

                    textWritter.WriteStartDocument();

                    textWritter.WriteStartElement("book");

                    textWritter.WriteEndElement();

                    textWritter.Close();
                   // Console.WriteLine("Xml have been created!");
                }
                else
                {
                    //Console.WriteLine("File haven't been created. Xml already exist!");

                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            addData(XmlFilePath,str);
        }
開發者ID:KateSenko,項目名稱:DocmToDocbook,代碼行數:30,代碼來源:DocBook.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: Build

        internal string Build()
        {
            using (MemoryStream ms = new MemoryStream())
            {
                using (XmlTextWriter xml = new XmlTextWriter(ms, new UTF8Encoding(false)) { Formatting = Formatting.Indented })
                {
                    xml.WriteStartDocument();

                    string license = this.GetLicense();
                    xml.WriteComment(license);

                    xml.WriteStartElement("MixERPReport");
                    xml.WriteElementString("Title", this.Definition.Title);

                    this.WriteTopSection(xml);
                    this.WriteBody(xml);
                    this.WriteBottomSection(xml);

                    this.WriteDataSources(xml);

                    this.WriteMenu(xml);
                }

                return Encoding.UTF8.GetString(ms.ToArray());
            }
        }
開發者ID:roczj,項目名稱:mixerp,代碼行數:26,代碼來源:ReportBuilder.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: 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

示例14: Main

        /* 08. Write a program, which (using XmlReader and XmlWriter) reads the file catalog.xml and creates the file album.xml,
         * in which stores in appropriate way the names of all albums and their authors.*/
        public static void Main()
        {
            using (XmlReader sr = XmlReader.Create("..\\..\\..\\catalog.xml"))
            {
                using (XmlTextWriter writer = new XmlTextWriter("..\\..\\album.xml", Encoding.UTF8))
                {
                    writer.WriteStartDocument();
                    writer.Formatting = Formatting.Indented;
                    writer.IndentChar = '\t';
                    writer.Indentation = 1;
                    writer.WriteStartElement("albums");
                    var name = string.Empty;
                    var artist = string.Empty;

                    while (sr.Read())
                    {
                        if ((sr.NodeType == XmlNodeType.Element) && (sr.Name == "name"))
                        {
                            name = sr.ReadElementString().Trim();
                        }
                        else if ((sr.NodeType == XmlNodeType.Element) && (sr.Name == "artist"))
                        {
                            artist = sr.ReadElementString().Trim();
                            WriteAlbumInnerXML(writer, name, artist);
                        }
                    }
                }
            }
        }
開發者ID:nkolarov,項目名稱:telerik-academy,代碼行數:31,代碼來源:ReadWriteXML.cs

示例15: Main

        static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            XmlDocument queryDocument = new XmlDocument();
            queryDocument.Load("../../reviews-queries.xml");
            using (XmlTextWriter writer = new XmlTextWriter("../../reviews-search-results.xml", Encoding.UTF8))
            {
                InitializeWriter(writer);

                writer.WriteStartDocument();
                writer.WriteStartElement("search-results");

                ReviewsDAO reviewsDao = new ReviewsDAO();

                using (LogsContext logsContext = new LogsContext())
                {
                    XmlNodeList queryNodes = queryDocument.SelectNodes("/review-queries/query");
                    foreach (XmlNode queryNode in queryNodes)
                    {
                        LogQuery(logsContext, queryNode.OuterXml);

                        WriteResultSet(writer, reviewsDao, queryNode);
                    }

                    writer.WriteEndDocument();
                }
            }

            Console.WriteLine("Done! See the file in project's directory.");
        }
開發者ID:vladislav-karamfilov,項目名稱:TelerikAcademy,代碼行數:31,代碼來源:ReviewsSearcherUI.cs


注:本文中的System.Xml.XmlTextWriter.WriteStartDocument方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。