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


C# XmlTextWriter.Close方法代码示例

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


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

示例1: FormatText

        static string FormatText(string text)
        {
            XmlTextWriter writer = null;
            XmlDocument doc = new XmlDocument();
            XmlWriterSettings xwSettings = new XmlWriterSettings();
            string formattedText = string.Empty;
            try
            {
                doc.LoadXml(text);

                writer = new XmlTextWriter(".data.xml", null);
                writer.Formatting = Formatting.Indented;
                doc.Save(writer);
                writer.Close();

                using (StreamReader sr = new StreamReader(".data.xml"))
                {
                    formattedText = sr.ReadToEnd();
                }
            }
            finally
            {
                File.Delete(".data.xml");
            }
            return formattedText;
        }
开发者ID:ayayalar,项目名称:functmetalnet,代码行数:26,代码来源:FunctMetaLRunner.cs

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

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

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

示例5: SetValue

        /// <summary>
        /// Define o valor de uma configuração
        /// </summary>
        /// <param name="file">Caminho do arquivo (ex: c:\program.exe.config)</param>
        /// <param name="key">Nome da configuração</param>
        /// <param name="value">Valor a ser salvo</param>
        /// <returns></returns>
        public static bool SetValue(string file, string key, string value)
        {
            var fileDocument = new XmlDocument();
            fileDocument.Load(file);
            var nodes = fileDocument.GetElementsByTagName(AddElementName);

            if (nodes.Count == 0)
            {
                return false;
            }

            for (var i = 0; i < nodes.Count; i++)
            {
                var node = nodes.Item(i);
                if (node == null || node.Attributes == null || node.Attributes.GetNamedItem(KeyPropertyName) == null)
                    continue;
                
                if (node.Attributes.GetNamedItem(KeyPropertyName).Value == key)
                {
                    node.Attributes.GetNamedItem(ValuePropertyName).Value = value;
                }
            }

            var writer = new XmlTextWriter(file, null) { Formatting = Formatting.Indented };
            fileDocument.WriteTo(writer);
            writer.Flush();
            writer.Close();
            return true;
        }
开发者ID:webbers,项目名称:dongle.net,代码行数:36,代码来源:AppConfig.cs

示例6: ToString

        public override string ToString()
        {
            string doc;

            using (var sw = new StringWriter()) {
                using (var writer = new XmlTextWriter(sw)) {
                    writer.Formatting = Formatting.Indented;
                    //writer.WriteStartDocument();
                    writer.WriteProcessingInstruction("xml", "version=\"1.0\" encoding=\"utf-8\"");
                    writer.WriteStartElement("D", "multistatus", "DAV:");
                    for (int i = 0; i < _nameSpaceList.Count; i++) {
                        string tag = string.Format("ns{0}", i);
                        writer.WriteAttributeString("xmlns", tag, null, _nameSpaceList[i]);
                    }

                    foreach (var oneResponse in _ar) {
                        oneResponse.Xml(writer);
                    }
                    writer.WriteEndElement();
                    //writer.WriteEndDocument();
                    writer.Flush();
                    writer.Close();
                    doc = sw.ToString();
                    writer.Flush();
                    writer.Close();
                }
                sw.Flush();
                sw.Close();
            }
            return doc;
        }
开发者ID:jsakamoto,项目名称:bjd5,代码行数:31,代码来源:PropFindResponce.cs

示例7: SaveBuildResultToFile

    internal void SaveBuildResultToFile(string preservationFile,
        BuildResult result, long hashCode) {

        _writer = new XmlTextWriter(preservationFile, Encoding.UTF8);

        try {
            _writer.Formatting = Formatting.Indented;
            _writer.Indentation = 4;
            _writer.WriteStartDocument();

            // <preserve assem="assemblyFile">
            _writer.WriteStartElement("preserve");

            // Save the type of BuildResult we're dealing with
            Debug.Assert(result.GetCode() != BuildResultTypeCode.Invalid); 
            SetAttribute("resultType", ((int)result.GetCode()).ToString(CultureInfo.InvariantCulture));

            // Save the virtual path for this BuildResult
            if (result.VirtualPath != null)
                SetAttribute("virtualPath", result.VirtualPath.VirtualPathString);

            // Get the hash code of the BuildResult
            long hash = result.ComputeHashCode(hashCode);

            // The hash should always be valid if we got here.
            Debug.Assert(hash != 0, "hash != 0"); 

            // Save it to the preservation file
            SetAttribute("hash", hash.ToString("x", CultureInfo.InvariantCulture));

            // Can be null if that's what the VirtualPathProvider returns
            string fileHash = result.VirtualPathDependenciesHash;
            if (fileHash != null)
                SetAttribute("filehash", fileHash);

            result.SetPreservedAttributes(this);

            SaveDependencies(result.VirtualPathDependencies);

            // </preserve>
            _writer.WriteEndElement();
            _writer.WriteEndDocument();

            _writer.Close();
        }
        catch {

            // If an exception occurs during the writing of the xml file, clean it up
            _writer.Close();
            File.Delete(preservationFile);

            throw;
        }
    }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:54,代码来源:PreservationFileWriter.cs

示例8: btnSalvar_Click

        private void btnSalvar_Click(object sender, EventArgs e)
        {
            XmlTextWriter myXmlTextWriter = new XmlTextWriter ("config.xml",System.Text.Encoding.UTF8);
            if (Verifica() != 0)
            {
                MessageBox.Show("Os campos com * precisam ser preenchidos.");
            }
            else
            {

                Conn.hostDB = textBox1.Text;
                Conn.Database = textBox2.Text;
                Conn.userDB = textBox3.Text;
                Conn.passwdDB = textBox4.Text;
                Conn.createStringConnection();

                try
                {

                    Conn.Conectar();

                    myXmlTextWriter.WriteStartElement("conectionstring");
                    myXmlTextWriter.WriteAttributeString("hostDB", textBox1.Text);
                    myXmlTextWriter.WriteAttributeString("database", textBox2.Text);
                    myXmlTextWriter.WriteAttributeString("userDB", textBox3.Text);
                    myXmlTextWriter.WriteAttributeString("passwordDB", textBox4.Text);
                    myXmlTextWriter.WriteEndElement();

                    //label6.Text = "Conectado";

                    Conn.ExecuteNonQueryFile("sql.sql");
                    myXmlTextWriter.Flush();
                    myXmlTextWriter.Close();
                    MessageBox.Show("Configuração Salva");
                    OK = true;
                    this.Close();

                }

                catch (Exception ex)
                {
                    MessageBox.Show("Não foi possível conectar. " + ex.Message);
                    myXmlTextWriter.Close();
                    File.Delete("config.xml");

                }

            }
        }
开发者ID:lucianaa,项目名称:winVenda,代码行数:49,代码来源:FormConfig.cs

示例9: CreateXml

        public void CreateXml()
        {
            if ( ( m_SeasonList.Count > 0 ) )
            {
                const string fileName = "NFL.xml";
                XmlTextWriter writer = new
                    XmlTextWriter(string.Format("{0}{1}", Utility.OutputDirectory() + "xml\\", fileName), null);
                writer.Formatting = Formatting.Indented;

                writer.WriteStartDocument();
                writer.WriteComment( "Comments: NFL Season List" );
                writer.WriteStartElement( "nfl" );
                writer.WriteStartElement("season-list");

                foreach ( NflSeason s in m_SeasonList )
                {
                    WriteSeasonNode( writer, s );
                }
                writer.WriteEndElement();
                writer.WriteEndElement();
                writer.WriteEndDocument();
                writer.Close();
                RosterLib.Utility.Announce( fileName + " created" );
            }
        }
开发者ID:Quarterback16,项目名称:GerardGui,代码行数:25,代码来源:NFL.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: Send

        /// <summary>
        /// Sends the specified API request.
        /// </summary>
        /// <param name="apiRequest">The API request.</param>
        /// <returns></returns>
        public ANetApiResponse Send(ANetApiRequest apiRequest) {

            //Authenticate it
            AuthenticateRequest(apiRequest);

            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(_serviceUrl);
            webRequest.Method = "POST";
            webRequest.ContentType = "text/xml";
            webRequest.KeepAlive = true;

            // Serialize the request
            var type = apiRequest.GetType();
            var serializer = new XmlSerializer(type);
            XmlWriter writer = new XmlTextWriter(webRequest.GetRequestStream(), Encoding.UTF8);
            serializer.Serialize(writer, apiRequest);
            writer.Close();


            // Get the response
            WebResponse webResponse = webRequest.GetResponse();

            // Load the response from the API server into an XmlDocument.
            _xmlDoc = new XmlDocument();
            _xmlDoc.Load(XmlReader.Create(webResponse.GetResponseStream()));


            var response = DecideResponse(_xmlDoc);
            CheckForErrors(response);
            return response;
        }
开发者ID:abansalm,项目名称:sdk-dotnet,代码行数:35,代码来源:HttpXmlUtility.cs

示例12: Serialize

        /// <summary>
        /// Serializes an object into an Xml Document
        /// </summary>
        /// <param name="o">The object to serialize</param>
        /// <returns>An Xml Document consisting of said object's data</returns>
        public static XmlDocument Serialize(object o)
        {
            XmlSerializer s = new XmlSerializer(o.GetType());

            MemoryStream ms = new MemoryStream();
            XmlTextWriter writer = new XmlTextWriter(ms, new UTF8Encoding());
            writer.Formatting = Formatting.Indented;
            writer.IndentChar = ' ';
            writer.Indentation = 5;
            Exception caught = null;

            try
            {
                s.Serialize(writer, o);
                XmlDocument xml = new XmlDocument();
                string xmlString = ASCIIEncoding.UTF8.GetString(ms.ToArray());
                xml.LoadXml(xmlString);
                return xml;
            }
            catch (Exception e)
            {
                caught = e;
            }
            finally
            {
                writer.Close();
                ms.Close();

                if (caught != null)
                    throw caught;
            }
            return null;
        }
开发者ID:jgennari,项目名称:NCR,代码行数:38,代码来源:Types.cs

示例13: XMLPrint

        public static String XMLPrint(this String xml){
            if (string.IsNullOrEmpty(xml))
                return xml;
            String result = "";

            var mStream = new MemoryStream();
            var writer = new XmlTextWriter(mStream, Encoding.Unicode);
            var document = new XmlDocument();

            try{
                document.LoadXml(xml);
                writer.Formatting = Formatting.Indented;
                document.WriteContentTo(writer);
                writer.Flush();
                mStream.Flush();
                mStream.Position = 0;
                var sReader = new StreamReader(mStream);
                String formattedXML = sReader.ReadToEnd();

                result = formattedXML;
            }
            catch (XmlException){
            }

            mStream.Close();
            writer.Close();

            return result;
        }
开发者ID:aries544,项目名称:eXpand,代码行数:29,代码来源:StringExtensions.cs

示例14: create

        public bool create(string xmlRoot, string fileName)
        {
            //create the root elements of the xml document if the dont alreasy exist
            try
            {
                if (!System.IO.File.Exists(fileName))
                {
                    XmlTextWriter xtw;
                    xtw = new XmlTextWriter(fileName, Encoding.UTF8);
                    xtw.WriteStartDocument();
                    xtw.WriteStartElement(xmlRoot);
                    xtw.WriteEndElement();
                    xtw.Close();

                    //if file exists return true
                    return true;
                }
                else { return false; }
            }
            catch (Exception err)
            {
                debugTerminal terminal = new debugTerminal();
                terminal.output(err.ToString());
                return false;
            }
        }
开发者ID:mattmarillac,项目名称:homestead-gui,代码行数:26,代码来源:dataBase.cs

示例15: GenerateReport

        public bool GenerateReport(string fileName)
        {
            bool retCode = false;
            ResetReportViwer();

            XslCompiledTransform xslt = new XslCompiledTransform();
            xslt.Load(rptXslPath);

            if ( File.Exists(fileName) == true)
            {
                XPathDocument myXPathDoc = new XPathDocument(fileName);
                StringWriter sw = new StringWriter();
                XmlWriter xmlWriter = new XmlTextWriter(sw);

                // using makes sure that we flush the writer at the end
                xslt.Transform(myXPathDoc, null, xmlWriter);
                xmlWriter.Flush();
                xmlWriter.Close();

                string xml = sw.ToString();

                HtmlDocument htmlDoc = axBrowser.Document;
                htmlDoc.Write(xml);
                retCode = true;
            }
            else
            {

                retCode = false;
            }

            return retCode;
        }
开发者ID:5dollartools,项目名称:NAM,代码行数:33,代码来源:ReportViewer.cs


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