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


C# XmlDocument.WriteTo方法代码示例

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


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

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

示例2: SerializeXml

        //ArrayList openElements = new ArrayList();
        public void SerializeXml(IList<StarSystem> starSystems)
        {
            MemoryStream memXmlStream = new MemoryStream();
            XmlSerializer serializer = new XmlSerializer(starSystems.GetType(), null, new Type[] { typeof(Planet), typeof(StarSystem) }, new XmlRootAttribute("Stars"), null, null);

            serializer.Serialize(memXmlStream, starSystems);

            XmlDocument xmlDoc = new XmlDocument();

            memXmlStream.Seek(0, SeekOrigin.Begin);
            xmlDoc.Load(memXmlStream);

            XmlProcessingInstruction newPI;
            String PItext = string.Format("type='text/xsl' href='{0}'", "system.xslt");
            newPI = xmlDoc.CreateProcessingInstruction("xml-stylesheet", PItext);

            xmlDoc.InsertAfter(newPI, xmlDoc.FirstChild);

            // Now write the document

            // out to the final output stream

            XmlTextWriter wr = new XmlTextWriter("system.xml", System.Text.Encoding.ASCII);
            wr.Formatting = Formatting.Indented;
            wr.IndentChar = '\t';
            wr.Indentation = 1;

            XmlWriterSettings settings = new XmlWriterSettings();
            XmlWriter writer = XmlWriter.Create(wr, settings);

            xmlDoc.WriteTo(writer);
            writer.Flush();
            //Console.Write(xmlDoc.InnerXml);
        }
开发者ID:sveco,项目名称:AccreteSharp,代码行数:35,代码来源:SystemDisplayXml.cs

示例3: GetInnerResponse

        protected override string GetInnerResponse()
        {
            XmlDocument doc = new XmlDocument();
            XmlElement musicFoldersElem = doc.CreateElement("musicFolders");

            List<string> musicFolders = this.GetExampleFolderNames();
            for (int i=1;i<=musicFolders.Count;i++)
            {
                XmlElement folder = doc.CreateElement("musicFolder");
                XmlAttribute idAttr = doc.CreateAttribute("id");
                XmlAttribute nameAttr = doc.CreateAttribute("name");
                idAttr.Value = i.ToString();
                nameAttr.Value = musicFolders[i-1];
                folder.Attributes.Append(idAttr);
                folder.Attributes.Append(nameAttr);
                musicFoldersElem.AppendChild(folder);
            }

            doc.AppendChild(musicFoldersElem);

            StringWriter sw = new StringWriter();
            XmlTextWriter xtw = new XmlTextWriter(sw);

            doc.WriteTo(xtw);

            return sw.ToString();
        }
开发者ID:tynorton,项目名称:subsonic-sharp,代码行数:27,代码来源:TestGetMusicFoldersResponse.cs

示例4: FixResource

        private string FixResource(string path)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(path);
            Regex rxName = new Regex(@".*\.(.*)\.DisplayName$");

            foreach (XmlNode node in doc.SelectNodes("//root/data/value"))
            {
                if (String.IsNullOrEmpty(node.InnerText) || node.InnerText == "Sage.Platform.Orm.Entities.OrmFieldProperty")
                {
                    String name = ((XmlElement)node.ParentNode).GetAttribute("name");
                    Match m = rxName.Match(name);
                    if (m.Success)
                    {
                        node.InnerText = m.Groups[1].Value;
                    }
                }
            }
            using (StringWriter buf = new StringWriter())
            {
                XmlWriterSettings settings = new XmlWriterSettings { Indent = true };
                using (XmlWriter w = XmlWriter.Create(buf, settings))
                {
                    doc.WriteTo(w);
                }
                return buf.GetStringBuilder().ToString();
            }
        }
开发者ID:nicocrm,项目名称:FixRes,代码行数:28,代码来源:FixResForm.cs

示例5: CreateKmlFile

 public static void CreateKmlFile(string fileName, IEnumerable<Location> locations)
 {
     try
     {
         var doc = new XmlDocument();
         var xdoc = new XDocument(
                           new XDeclaration("1.0", Encoding.UTF8.HeaderName, String.Empty),
                           new XElement(Kmlns + "kml",
                           new XElement(Kmlns + "Document",
                           new XElement(Kmlns + "name", "None"),
                           new XElement(Kmlns + "Style",
                           new XAttribute("id", "defaultStyle"),
                           new XElement(Kmlns + "LineStyle", new XElement(Kmlns + "color", "ffffffff"), new XElement(Kmlns + "colorMode", "normal"), new XElement(Kmlns + "width", 1)),
                           new XElement(Kmlns + "PolyStyle", new XElement(Kmlns + "color", "880000ff"), new XElement(Kmlns + "colorMode", "normal"), new XElement(Kmlns + "fill", 1), new XElement(Kmlns + "outline", 1))),
                           BuildGeographicPolylineType("FoV", locations))));
         doc.LoadXml(xdoc.Root.ToString());
         using (var writer = XmlWriter.Create(fileName))
         {
             doc.WriteTo(writer);
         }
     }
     catch (Exception)
     {
         Console.WriteLine("Could not create KML file!!!!");
     }
 }
开发者ID:TNOCS,项目名称:csTouch,代码行数:26,代码来源:KML.cs

示例6: WriteGzip

		public static void WriteGzip(XmlDocument theDoc, Stream theStream)
		{
			MemoryStream ms = new MemoryStream();
			XmlWriterSettings xmlSettings = new XmlWriterSettings();

			xmlSettings.Encoding = Encoding.UTF8;
			xmlSettings.ConformanceLevel = ConformanceLevel.Document;
			xmlSettings.Indent = false;
			xmlSettings.NewLineOnAttributes = false;
			xmlSettings.CheckCharacters = true;
			xmlSettings.IndentChars = "";

			XmlWriter tw = XmlWriter.Create(ms, xmlSettings);

			theDoc.WriteTo(tw);
			tw.Flush();
			tw.Close();

			byte[] buffer = ms.GetBuffer();

			GZipStream compressedzipStream = new GZipStream(theStream, CompressionMode.Compress, true);
			compressedzipStream.Write(buffer, 0, buffer.Length);
			// Close the stream.
			compressedzipStream.Flush();
			compressedzipStream.Close();

			// Force a flush
			theStream.Flush();
		}
开发者ID:scottshea,项目名称:monodicom,代码行数:29,代码来源:StudyXmlIo.cs

示例7: Write

        public bool Write(Database database, StreamWriter stream, bool encrypt = true)
        {
            // Clear the last error
            this.ErrorString = string.Empty;

            XmlDocument document = new XmlDocument();
            this.Append(document, document, database);

            StringWriter sw = new StringWriter();
            XmlTextWriter xw = new XmlTextWriter(sw);
            xw.Formatting = Formatting.Indented;
            xw.Indentation = 4;
            document.WriteTo(xw);
            string fileDataString = sw.ToString();

            if (encrypt)
            {
                DatabaseCrypto.CryptoStatus status;
                fileDataString = DatabaseCrypto.Encrypt(fileDataString, database.Password, database.Compression, out status);
                if (status != DatabaseCrypto.CryptoStatus.NoError)
                {
                    this.ErrorString = DatabaseCrypto.StatusMessage(status);
                    return false;
                }
            }

            stream.Write(fileDataString);
            return true;
        }
开发者ID:petroules,项目名称:silverlock,代码行数:29,代码来源:DatabaseWriter.cs

示例8: PrettyPrint

        public static string PrettyPrint(XmlDocument xml)
        {
            var result = "";

            if (xml == null)
                return result;

            using (var ms = new MemoryStream())
            {
                var writer = new XmlTextWriter(ms, Encoding.Unicode);
                writer.Formatting = Formatting.Indented;

                xml.WriteTo(writer);

                writer.Flush();
                ms.Flush();

                ms.Position = 0;

                var reader = new StreamReader(ms);
                result = reader.ReadToEnd();

                writer.Close();
                reader.Close();

            }

            return result;
        }
开发者ID:jmacnico,项目名称:Proxmulator,代码行数:29,代码来源:Utils.cs

示例9: Transform

        /// <summary>
        /// Transform: read from an input stream and write to an output stream.
        /// </summary>
        public void Transform(Stream inputStream, Stream outputStream)
        {
            var document = new XmlDocument();
            document.PreserveWhitespace = true;
            document.Load(inputStream);

            foreach (XmlNode node in document.SelectNodes("/root/data/value"))
            {
                var child = node.FirstChild;
                if (child != null && child.NodeType == XmlNodeType.Text)
                {
                    var original = child.Value;
                    var args = new TransformStringEventArgs { Value = original };
                    OnTransformString(args);

                    if (args.Value != original)
                    {
                        child.Value = args.Value;
                    }
                }
            }

            using (var xmlWriter = XmlWriter.Create(outputStream))
            {
                document.WriteTo(xmlWriter);
            }
        }
开发者ID:anderskaplan,项目名称:Pseudolocalizer,代码行数:30,代码来源:ResxProcessor.cs

示例10: GetXmlDocumentAsString

        private string GetXmlDocumentAsString(XmlDocument xml)
        {
            var xmlString = string.Empty;

            using (var stream = new MemoryStream())
            {
                using (var streamWriter = new StreamWriter(stream))
                {
                    var xmlWriterSettings = new XmlWriterSettings();
                    xmlWriterSettings.Encoding = Encoding.UTF8;
                    xmlWriterSettings.Indent = true;

                    using (var xmlWriter = XmlWriter.Create(streamWriter, xmlWriterSettings))
                    {
                        xml.WriteTo(xmlWriter);
                        xmlWriter.Flush();
                        xmlWriter.Close();
                    }

                    using (var streamReader = new StreamReader(stream))
                    {
                        stream.Position = 0;
                        xmlString = streamReader.ReadToEnd();
                        streamReader.Close();
                    }
                }
            }

            return xmlString;
        }
开发者ID:GeekInTheNorth,项目名称:HmrcDpsTestServer,代码行数:30,代码来源:CascadeEdgeCaseService.cs

示例11: Write

 /// <summary>
 /// Converts a XmlDocument to string
 /// </summary>
 /// <param name="doc">XmlDocument to be converted</param>
 /// <returns>string with the xml content</returns>
 public static string Write(XmlDocument doc)
 {
     StringWriter sw = new StringWriter();
     XmlWriter xw = new XmlTextWriter(sw);
     doc.WriteTo(xw);
     return sw.ToString();
 }
开发者ID:ziyan,项目名称:reactivity,代码行数:12,代码来源:Xml.cs

示例12: Create

 public ActionResult Create(string webConfigXml, string transformXml)
 {
     try
     {
         var transformation = new XmlTransformation(transformXml, false, null);
         var document = new XmlDocument();
         document.LoadXml(webConfigXml);
         var success = transformation.Apply(document);
         if (success)
         {
             var stringBuilder = new StringBuilder();
             var xmlWriterSettings = new XmlWriterSettings();
             xmlWriterSettings.Indent = true;
             xmlWriterSettings.IndentChars = "    ";
             using (var xmlTextWriter =
                 XmlTextWriter.Create(stringBuilder, xmlWriterSettings))
             {
                 document.WriteTo(xmlTextWriter);
             }
             return Content(stringBuilder.ToString(), "text/xml");
         }
         else
         {
             return ErrorXml("Transformation failed for unkown reason");
         }
     }
     catch (XmlTransformationException xmlTransformationException)
     {
         return ErrorXml(xmlTransformationException.Message);
     }
     catch (XmlException xmlException)
     {
         return ErrorXml(xmlException.Message);
     }
 }
开发者ID:ryoe,项目名称:appharbor-transformtester,代码行数:35,代码来源:TransformController.cs

示例13: CreateXml

        public string CreateXml(XmlDocument doc, string cookie, int page, int count)
        {
            if (doc.DocumentElement == null)
                throw new ArgumentNullException("DocumentElement");

            XmlAttributeCollection attrs = doc.DocumentElement.Attributes;

            if (cookie != null)
            {
                XmlAttribute pagingAttr = doc.CreateAttribute("paging-cookie");
                pagingAttr.Value = cookie;
                attrs.Append(pagingAttr);
            }

            XmlAttribute pageAttr = doc.CreateAttribute("page");
            pageAttr.Value = System.Convert.ToString(page);
            attrs.Append(pageAttr);

            XmlAttribute countAttr = doc.CreateAttribute("count");
            countAttr.Value = System.Convert.ToString(count);
            attrs.Append(countAttr);

            StringBuilder sb = new StringBuilder(1024);
            StringWriter stringWriter = new StringWriter(sb);

            XmlTextWriter writer = new XmlTextWriter(stringWriter);
            doc.WriteTo(writer);
            writer.Close();

            return sb.ToString();
        }
开发者ID:philipstathis,项目名称:Deduplicator_XrmToolBox_Plugin,代码行数:31,代码来源:Main.cs

示例14: PrettyPrintXml

        /// <summary>
        /// Converts the given XML string into a more readable format.
        /// </summary>
        internal static string PrettyPrintXml(string xml)
        {
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.OmitXmlDeclaration = true;
            settings.ConformanceLevel = ConformanceLevel.Fragment;
            settings.NewLineHandling = NewLineHandling.Replace;
            settings.NewLineChars = "\r\n";
            settings.Indent = true;
            settings.IndentChars = "\t";
            settings.NewLineOnAttributes = true;

            XmlDocument doc = new XmlDocument();
            try
            {
                doc.LoadXml(xml);
            }
            catch (Exception e)
            {
                throw new Exception("Invalid XML: " + xml, e);
            }

            var sb = new StringBuilder();
            using (var writer = XmlTextWriter.Create(sb, settings))
                doc.WriteTo(writer);

            return sb.ToString();
        }
开发者ID:vc3,项目名称:ExoWeb,代码行数:30,代码来源:BaseRenderTests.cs

示例15: Upgrades0210

        // Accumulation format is now called Victory.
        private static void Upgrades0210()
        {
            var xml = new XmlDocument();
            if (Config.Settings.SeparateEventFiles)
            {
                var targetPath = Path.Combine(Program.BasePath, "Tournaments");
                if (!Directory.Exists(targetPath)) Directory.CreateDirectory(targetPath);
                var files = new List<string>(Directory.GetFiles(targetPath, "*.tournament.dat",
                    SearchOption.TopDirectoryOnly));
                files.AddRange(Directory.GetFiles(targetPath, "*.league.dat",
                    SearchOption.TopDirectoryOnly));
                foreach (string filename in files)
                {
                    xml.Load(filename);
                    var oldNodes = xml.SelectNodes("//Events/Tournaments/Tournament/Format[. = 'Accumulation']");
                    if (oldNodes != null)
                        foreach (XmlNode oldNode in oldNodes)
                            oldNode.InnerText = "Victory";
                    oldNodes = xml.SelectNodes("//Events/Leagues/League/Format[. = 'Accumulation']");
                    if (oldNodes != null)
                        foreach (XmlNode oldNode in oldNodes)
                            oldNode.InnerText = "Victory";

                    var writer = new XmlTextWriter(new FileStream(filename, FileMode.Create), null)
                        {
                            Formatting = Formatting.Indented,
                            Indentation = 1,
                            IndentChar = '\t'
                        };

                    xml.WriteTo(writer);
                    writer.Flush();
                    writer.Close();
                }
            }
            else if (File.Exists(Path.Combine(Program.BasePath, "Events.dat")))
            {
                xml.Load(Path.Combine(Program.BasePath, "Events.dat"));
                var oldNodes = xml.SelectNodes("//Events/Tournaments/Tournament/Format[. = 'Accumulation']");
                if (oldNodes != null)
                    foreach (XmlNode oldNode in oldNodes)
                        oldNode.InnerText = "Victory";
                oldNodes = xml.SelectNodes("//Events/Leagues/League/Format[. = 'Accumulation']");
                if (oldNodes != null)
                    foreach (XmlNode oldNode in oldNodes)
                        oldNode.InnerText = "Victory";

                var writer = new XmlTextWriter(new FileStream(Path.Combine(Program.BasePath,
                                                                           "Events.dat"), FileMode.Create), null)
                {
                    Formatting = Formatting.Indented,
                    Indentation = 1,
                    IndentChar = '\t'
                };

                xml.WriteTo(writer);
                writer.Flush();
                writer.Close();
            }
        }
开发者ID:DeusInnomen,项目名称:LuciusIncidentLogbook,代码行数:61,代码来源:Upgrades.cs


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