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


C# XmlDocument.WriteContentTo方法代码示例

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


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

示例1: Execute

        public bool Execute()
        {
            if (!File.Exists(WebConfig))
                return false;

            var fileContents = new XmlDocument();
            fileContents.Load(WebConfig);

            var nodes = fileContents.SelectNodes("/configuration/system.serviceModel/client/endpoint");

            if (nodes == null || nodes.Count == 0)
                return false;

            foreach(var node in nodes)
            {
                var address = (node as XmlNode).Attributes["address"].Value;

                var splitAddress = address.Split('/');

                var newAddress = Url + "/" + address[address.Length - 1];

                (node as XmlNode).Attributes["address"].Value = newAddress;
            }

            using (var writer = XmlWriter.Create(WebConfig))
            {
                fileContents.WriteContentTo(writer);
            }

            return true;
        }
开发者ID:bridgeharringtonc,项目名称:updateassemblyversion,代码行数:31,代码来源:UpdateEndpointTask.cs

示例2: FormatXml

        public static String FormatXml(String value)
        {
            using (var mStream = new MemoryStream())
            {
                using (var writer = new XmlTextWriter(mStream, Encoding.Unicode) { Formatting = System.Xml.Formatting.Indented})
                {
                    var document = new XmlDocument();
                    try
                    {
                        document.LoadXml(value);

                        document.WriteContentTo(writer);
                        writer.Flush();
                        mStream.Flush();

                        mStream.Position = 0;
                        var sReader = new StreamReader(mStream);

                        return sReader.ReadToEnd();
                    }
                    catch (XmlException)
                    {
                    }
                }
            }
            return value;
        }
开发者ID:moldypenguins,项目名称:manictime-server-sampleclient,代码行数:27,代码来源:ResultFormatter.cs

示例3: FormatXml

        public static String FormatXml(String xml)
        {
            var mStream = new MemoryStream();
            var document = new XmlDocument();
            var writer = new XmlTextWriter(mStream, Encoding.Unicode)
            {
                Formatting = Formatting.Indented
            };

            try
            {
                document.LoadXml(xml);
                document.WriteContentTo(writer);

                writer.Flush();

                mStream.Flush();
                mStream.Position = 0;

                var sReader = new StreamReader(mStream);

                return sReader.ReadToEnd();
            }
            catch (XmlException)
            {
                return string.Empty;
            }
            finally
            {
                mStream.Close();
                writer.Close();
            }
        }
开发者ID:RichardPriddy,项目名称:SharePointRepository,代码行数:33,代码来源:ListOfIntExtensionMenthods.cs

示例4: PrepareComponentUpdateXml

        private static string PrepareComponentUpdateXml(string xmlpath, IDictionary<string, string> paths)
        {
            string xml = File.ReadAllText(xmlpath);

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xml);

            XmlNamespaceManager manager = new XmlNamespaceManager(doc.NameTable);
            manager.AddNamespace("avm", "avm");
            manager.AddNamespace("cad", "cad");

            XPathNavigator navigator = doc.CreateNavigator();
            var resourceDependencies = navigator.Select("/avm:Component/avm:ResourceDependency", manager).Cast<XPathNavigator>()
                .Concat(navigator.Select("/avm:Component/ResourceDependency", manager).Cast<XPathNavigator>());
            
            foreach (XPathNavigator node in resourceDependencies)
            {
                string path = node.GetAttribute("Path", "avm");
                if (String.IsNullOrWhiteSpace(path))
                {
                    path = node.GetAttribute("Path", "");
                }
                string newpath;
                if (paths.TryGetValue(node.GetAttribute("Name", ""), out newpath))
                {
                    node.MoveToAttribute("Path", "");
                    node.SetValue(newpath);
                }
            }
            StringBuilder sb = new StringBuilder();
            XmlTextWriter w = new XmlTextWriter(new StringWriter(sb));
            doc.WriteContentTo(w);
            w.Flush();
            return sb.ToString();
        }
开发者ID:neemask,项目名称:meta-core,代码行数:35,代码来源:CyPhyMLPropagateTest.cs

示例5: SaveProfile

        public static bool SaveProfile(XmlDocument xml, string path)
        {

            XmlTextWriter textWriter = null;
            FileStream fs = null;
            try
            {
                fs = new FileStream(path, FileMode.OpenOrCreate);
                textWriter = new XmlTextWriter(fs, Encoding.UTF8);
                textWriter.Formatting = Formatting.Indented;
                xml.WriteContentTo(textWriter);
            }
            catch (IOException io)
            {
                //TODO : Error Log
                Console.WriteLine(io.StackTrace);
                return false;
            }
            finally
            {
                if (textWriter != null)
                {
                    try
                    {
                        textWriter.Close();
                    }
                    catch (Exception)
                    {
                    }
                }

            }
            return true;
        }
开发者ID:sr3dna,项目名称:big5sync,代码行数:34,代码来源:ProfilingXMLHelper.cs

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

示例7: button2_Click

        private void button2_Click(object sender, EventArgs e)
        {
            XmlDocument doc = new XmlDocument();
            //To create the XML DOM Tree
            doc.Load(@"D:\MS.Net\CSharp\XMLParser\XMLParser\Emp.xml");

            XmlElement emp = doc.CreateElement("Emp");
            XmlElement eid = doc.CreateElement("EId");
            XmlElement enm = doc.CreateElement("EName");
            XmlElement bs = doc.CreateElement("Basic");
            eid.InnerText = textBox1.Text;
            enm.InnerText = textBox2.Text;
            bs.InnerText = textBox3.Text;
            emp.AppendChild(eid);
            emp.AppendChild(enm);
            emp.AppendChild(bs);
            emp.SetAttribute("Department", textBox4.Text);
            emp.SetAttribute("Designation", textBox5.Text);
            doc.DocumentElement.AppendChild(emp);
            //Writing to file
            XmlTextWriter tr =
                new XmlTextWriter(@"D:\MS.Net\CSharp\XMLParser\XMLParser\Emp.xml", null);
            tr.Formatting = Formatting.Indented;
            doc.WriteContentTo(tr);
            tr.Close();//save the changes
        }
开发者ID:prijuly2000,项目名称:Dot-Net,代码行数:26,代码来源:Form1.cs

示例8: PrettyPrintXml

        void PrettyPrintXml(string xml)
        {
            var document = new XmlDocument();

            try
            {
                document.LoadXml(xml);
                using (var stream = new MemoryStream())
                {
                    using (var writer = new XmlTextWriter(stream, Encoding.Unicode))
                    {

                        writer.Formatting = System.Xml.Formatting.Indented;
                        document.WriteContentTo(writer);
                        writer.Flush();
                        stream.Flush();
                        stream.Position = 0;

                        var reader = new StreamReader(stream);
                        xml = reader.ReadToEnd();
                    }
                }
            }
            catch (XmlException)
            {
            }
        }
开发者ID:codeprogression,项目名称:OptionStrict.oEmbed,代码行数:27,代码来源:OembedView.cs

示例9: IndentXMLString

        /// <summary>
        /// Auto-formats and indents an unformatted XML string.
        /// </summary>
        /// <param name="xml"></param>
        /// <returns></returns>
        private static string IndentXMLString(string xml)
        {
            string outXml = string.Empty;
            MemoryStream ms = new MemoryStream();
            // Create a XMLTextWriter that will send its output to a memory stream (file)
            XmlTextWriter xtw = new XmlTextWriter(ms, Encoding.Unicode);
            XmlDocument doc = new XmlDocument();

            // Load the unformatted XML text string into an instance
            // of the XML Document Object Model (DOM)
            doc.LoadXml(xml);

            // Set the formatting property of the XML Text Writer to indented
            // the text writer is where the indenting will be performed
            xtw.Formatting = Formatting.Indented;

            // write dom xml to the xmltextwriter
            doc.WriteContentTo(xtw);
            // Flush the contents of the text writer
            // to the memory stream, which is simply a memory file
            xtw.Flush();

            // set to start of the memory stream (file)
            ms.Seek(0, SeekOrigin.Begin);
            // create a reader to read the contents of
            // the memory stream (file)
            StreamReader sr = new StreamReader(ms);
            // return the formatted string to caller
            return sr.ReadToEnd();
        }
开发者ID:nefarius,项目名称:CitrixConfigurator,代码行数:35,代码来源:MainWindow.cs

示例10: WriteToStream

 private void WriteToStream(XmlDocument document, Stream stream)
 {
     XmlTextWriter writer = new XmlTextWriter(stream, Encoding.GetEncoding("ISO-8859-1"));
     writer.Formatting = Formatting.Indented;
     writer.Indentation = 4;
     writer.IndentChar = ' ';
     document.WriteContentTo(writer);
     writer.Close();
 }
开发者ID:mazhaojia,项目名称:XMLEditor,代码行数:9,代码来源:ShowCmd.cs

示例11: ReformatXmlString

        private static MemoryStream ReformatXmlString(string xmlstream)
        {
            MemoryStream stream = new MemoryStream();
            XmlTextWriter formatter = new XmlTextWriter(stream, Encoding.UTF8);
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xmlstream);
            formatter.Formatting = Formatting.Indented;
            doc.WriteContentTo(formatter);
            formatter.Flush();
            return stream;
        }
开发者ID:BogusCurry,项目名称:halcyon,代码行数:12,代码来源:SerialiseObjects.cs

示例12: SaveXmlInStream

 /**
  * Turning the DOM4j object in the specified output stream.
  *
  * @param xmlContent
  *            The XML document.
  * @param outStream
  *            The Stream in which the XML document will be written.
  * @return <b>true</b> if the xml is successfully written in the stream,
  *         else <b>false</b>.
  */
 public static void SaveXmlInStream(XmlDocument xmlContent,
         Stream outStream)
 {
     //XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlContent.NameTable);
     //nsmgr.AddNamespace("", "");
     XmlWriterSettings settings = new XmlWriterSettings();
     settings.Encoding = Encoding.UTF8;
     settings.OmitXmlDeclaration = false;
     XmlWriter writer = XmlTextWriter.Create(outStream,settings);
     //XmlWriter writer = new XmlTextWriter(outStream,Encoding.UTF8);
     xmlContent.WriteContentTo(writer);
     writer.Flush();
 }
开发者ID:JnS-Software-LLC,项目名称:npoi,代码行数:23,代码来源:StreamHelper.cs

示例13: Main

        static void Main(string[] args)
        {
#if DEBUG 
            args = new string[] { "d:\\projects\\csharp\\csquery\\build\\csquery.nuspec", "d:\\projects\\csharp\\csquery\\build\\csquery.test.nuspec", "-version", "1" };
#endif
            if (args.Length < 4 || args.Length % 2 != 0)
            {
                Console.WriteLine("Call with: ProcessNuspec input output [-param value] [-param value] ...");
                Console.WriteLine("e.g. ProcessNuspec../source/project.nuspec.template ../source/project.nuspec -version 1.3.3 -id csquery");
            }


            string input = Path.GetFullPath(args[0]);
            string output = Path.GetFullPath(args[1]);

            int argPos = 2;

            var dict = new Dictionary<string, string>();
            while (argPos < args.Length)
            {
                var argName = args[argPos++];
                var argValue = args[argPos++];
                if (!argName.StartsWith("-")) {
                    throw new Exception("Every argument must be a -name/value pair.");
                }
                dict[argName.Substring(1)]=argValue;
            }
           

            XmlDocument xDoc = new XmlDocument();
            xDoc.Load(input);

            foreach (var item in dict) {
                
                var nodes = xDoc.DocumentElement.SelectNodes("//" + item.Key );
                if (nodes.Count == 1)
                {
                    var node = nodes[0];
                    if (dict.ContainsKey(node.Name) && node.ChildNodes.Count==1)
                    {
                        node.ChildNodes[0].Value = item.Value;
                    }
                }
            }
            //string outputText = "<?xml version=\"1.0\"?>";
            XmlWriter writer = XmlWriter.Create(output);
            xDoc.WriteContentTo(writer);
            writer.Flush();
            writer.Close();

        }
开发者ID:emrahoner,项目名称:CsQuery,代码行数:51,代码来源:Program.cs

示例14: LoadDocumentIntoMessage

        private byte[] LoadDocumentIntoMessage(XmlDocument doc)
        {
            Stream ms = new MemoryStream();
            XmlDictionaryWriter writer = XmlDictionaryWriter.CreateBinaryWriter(ms, _wcfBinaryDictionary);

            doc.WriteContentTo(writer);
            writer.Flush();

            byte[] bb = new byte[ms.Length];
            ms.Seek(0, SeekOrigin.Begin);
            ms.Read(bb, 0, (int)ms.Length);

            return bb;
        }
开发者ID:xiaoyao9184,项目名称:AQISet,代码行数:14,代码来源:WCFMessageHelper.cs

示例15: ConvertXmlToWcfBinary

 public static byte[] ConvertXmlToWcfBinary(XmlDocument document)
 {
     byte[] binaryContent = null;
     using (MemoryStream ms = new MemoryStream())
     {
         XmlDictionaryWriter binaryWriter = XmlDictionaryWriter.CreateBinaryWriter(ms);
         document.WriteContentTo(binaryWriter);
         binaryWriter.Flush();
         ms.Position = 0;
         int length = int.Parse(ms.Length.ToString());
         binaryContent = new byte[length];
         ms.Read(binaryContent, 0, length);
         ms.Flush();
     }
     return binaryContent;
 }
开发者ID:huoxudong125,项目名称:WCF-Binary-Message-Inspector,代码行数:16,代码来源:WcfBinaryConverter.cs


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