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


C# XElement.WriteTo方法代码示例

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


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

示例1: Create

        public static string Create(CasperJsTestsResults casperJsTestsResults)
        {
            XNamespace testRunNamespace =
                XNamespace.Get("http://microsoft.com/schemas/VisualStudio/TeamTest/2010");

            var xml = new XElement("TestRun",
                new XAttribute("id", Guid.NewGuid().ToString()),
                new XElement("ResultSummary",
                    new XAttribute("outcome", "Completed"),
                    new XElement("Counters",
                        new XAttribute("total", (casperJsTestsResults.PassedTests.Count + casperJsTestsResults.FailedTests.Count).ToString()),
                        new XAttribute("passed", casperJsTestsResults.PassedTests.Count.ToString()),
                        new XAttribute("failed", casperJsTestsResults.FailedTests.Count.ToString()))),
                new XElement("TestDefinitions",
                    GetUnitTestsDefinitions(casperJsTestsResults)),
                new XElement("TestEntries",
                    GetUnitTestsEntries(casperJsTestsResults)),
                new XElement("Results",
                    GetUnitTestsResults(casperJsTestsResults))
                );

            var xDocument = new XDocument(xml);

            xDocument.Root.Name = testRunNamespace + xDocument.Root.Name.LocalName;

            using (var textWriter = new StringWriter())
            {
                using (XmlWriter xmlWriter = XmlWriter.Create(textWriter))
                {
                    xml.WriteTo(xmlWriter);
                }
                return textWriter.ToString();
            }
        }
开发者ID:vgaltes,项目名称:CasperJSCustomBuildActivity,代码行数:34,代码来源:CasperJsTrxCreator.cs

示例2: XmlTest

    void XmlTest()
    {
        XElement root = new XElement ("root");
        for (int i = 0; i < 3; i ++) {
            XElement item = new XElement ("item");
            item.Add (new XAttribute ("1item" + i.ToString (), i));
            item.Add (new XAttribute ("2item" + i.ToString (), i));
            item.Add (new XAttribute ("3item" + i.ToString (), i));
        }
        using (FileStream fs = new FileStream( Application.dataPath + "/test.xml",FileMode.Create)) {
            XmlWriterSettings setting = new XmlWriterSettings ();
            setting.Indent = true;
            setting.IndentChars = "\t";
            setting.NewLineChars = "\n";
            setting.Encoding = Encoding.UTF8;
            using (XmlWriter xw = XmlWriter.Create(fs, setting)) {
                root.WriteTo (xw);
            }
        }

        //		using(FileStream fs = new FileStream( FILE_DIR + "/" + "ServerConfig/terrainEditorConfig.xml", FileMode.Create ) )
        //		{
        //			XmlWriterSettings setting = new XmlWriterSettings();
        //			setting.Indent = true;
        //			setting.IndentChars = "\t";
        //			setting.NewLineChars = "\n";
        //			setting.Encoding = Encoding.UTF8;
        //			using (XmlWriter xw = XmlWriter.Create(fs, setting))
        //			{
        //				root.WriteTo(xw);
        //			}
        //		}
        //	}
    }
开发者ID:haodengli,项目名称:UnityTool,代码行数:34,代码来源:NewBehaviourScript.cs

示例3: WriteElement

		internal static void WriteElement(XmlWriter writer, XElement element)
		{
			if (WriteWholeNode(element))
			{
				// Write entire element in one gulp, to avoid eating needed spaces in <Run> elements.
				element.WriteTo(writer);
			}
			else
			{
				writer.WriteStartElement(element.Name.LocalName);
				foreach (var attribute in element.Attributes())
				{
					writer.WriteAttributeString(attribute.Name.LocalName, attribute.Value);
				}
				if (element.HasElements)
				{
					foreach (var childNode in element.Elements().ToArray())
					{
						// Recurse on down to the bottom.
						WriteElement(writer, childNode);
						childNode.Remove();
					}
				}
				else
				{
					if (!string.IsNullOrEmpty(element.Value))
						writer.WriteString(element.Value);
				}
				writer.WriteEndElement();
			}
		}
开发者ID:gmartin7,项目名称:flexbridge,代码行数:31,代码来源:FileWriterService.cs

示例4: WriteTo

        public static void WriteTo(Bundle bundle, XmlWriter writer, bool summary = false)
        {
            if (bundle == null) throw new ArgumentException("Bundle cannot be null");

            var root = new XElement(BundleXmlParser.XATOMNS + BundleXmlParser.XATOM_FEED);

            if (!String.IsNullOrWhiteSpace(bundle.Title)) root.Add(xmlCreateTitle(bundle.Title));
            if (SerializationUtil.UriHasValue(bundle.Id)) root.Add(xmlCreateId(bundle.Id));
            if (bundle.LastUpdated != null) root.Add(new XElement(BundleXmlParser.XATOMNS + BundleXmlParser.XATOM_UPDATED, bundle.LastUpdated));

            if (!String.IsNullOrWhiteSpace(bundle.AuthorName))
                root.Add(xmlCreateAuthor(bundle.AuthorName, bundle.AuthorUri));
            if (bundle.TotalResults != null) root.Add(new XElement(BundleXmlParser.XOPENSEARCHNS + BundleXmlParser.XATOM_TOTALRESULTS, bundle.TotalResults));

            if (bundle.Links != null)
            {
                foreach (var l in bundle.Links)
                    root.Add(xmlCreateLink(l.Rel, l.Uri));
            }

            if (bundle.Tags != null)
            {
                foreach (var tag in bundle.Tags)
                    root.Add(TagListSerializer.CreateTagCategoryPropertyXml(tag));
            }

            foreach (var entry in bundle.Entries)
                root.Add(createEntry(entry, summary));

            root.WriteTo(writer);
            //var result = new XDocument(root);
            //result.WriteTo(writer);
        }
开发者ID:ranjancse26,项目名称:fhir-net-api,代码行数:33,代码来源:BundleXmlSerializer.cs

示例5: XElementToString

 public static string XElementToString(XElement xml)
 {
     var sw = new StringWriterUTF8(CultureInfo.CurrentCulture);
     var writer = XmlWriter.Create(sw, new XmlWriterSettings() { Indent = true, IndentChars = "\t", Encoding = Encoding.UTF8 });
     xml.WriteTo(writer);
     writer.Flush();
     writer.Close();
     return sw.ToString();
 }
开发者ID:jprichardson,项目名称:CommonLib,代码行数:9,代码来源:StringUtil.cs

示例6: SaveXElementUsingXmlWriter

 private string SaveXElementUsingXmlWriter(XElement elem, NamespaceHandling nsHandling)
 {
     StringWriter sw = new StringWriter();
     using (XmlWriter w = XmlWriter.Create(sw, new XmlWriterSettings() { NamespaceHandling = nsHandling, OmitXmlDeclaration = true }))
     {
         elem.WriteTo(w);
     }
     sw.Dispose();
     return sw.ToString();
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:10,代码来源:OmitDuplicateNamespaceDecl.cs

示例7: Write

		public void Write(Interaction interaction) {
			var tree = new XElement("tape",
			    new XElement("interaction", 
					MapRequest(interaction.Request),
			        MapResponse(interaction.Response)
			    )
			);
			
			tree.WriteTo(writer);
		}
开发者ID:dylanmei,项目名称:magnetic.tapes,代码行数:10,代码来源:XmlTapeWriter.cs

示例8: WriteResponse

        public async Task WriteResponse(XElement feed)
        {
            ResponseContentType = "application/atom+xml; type=feed; charset=utf-8";

            MemoryStream stream = new MemoryStream();
            XmlWriter writer = XmlWriter.Create(stream);
            feed.WriteTo(writer);
            writer.Flush();
            byte[] data = stream.ToArray();

            await WriteResponseAsync(data);
        }
开发者ID:sistoimenov,项目名称:NuGet2,代码行数:12,代码来源:InterceptCallContext.cs

示例9: Write

        // Private Methods
        //======================================================================

        private void Write(XmlWriter outputWriter)
        {
            outputWriter.WriteStartDocument();

            XElement root = new XElement(Xmlns + "Image",
                new XAttribute("TileSize", DefaultTileSize),
                new XAttribute("Overlap", DefaultOverlap),
                new XAttribute("Format", DefaultFormat),
                new XElement(Xmlns + "Size",
                        new XAttribute("Width", m_size.Width),
                        new XAttribute("Height", m_size.Height)));
            root.WriteTo(outputWriter);
        }
开发者ID:lramctr,项目名称:Lakshmi-Files,代码行数:16,代码来源:DziSerializer.cs

示例10: Table

        public virtual void Table(TextWriter writer)
        {
            var tab = new XElement("table"
                , new XAttribute("id", "postGrid")
                , new XAttribute("class", "list"));

            var th = TableHeader();
            tab.Add(th);

            foreach (object row in ReadData())
                tab.Add(row);

            tab.WriteTo(XmlWriter.Create(writer));
        }
开发者ID:akrisiun,项目名称:git-dot-aspx,代码行数:14,代码来源:IRenderTable.cs

示例11: OnProcessRecord

        protected override void OnProcessRecord()
        {
            var netConfig = new XElement(
                NetconfigNamespace + "NetworkConfiguration",
                new XAttribute("xmlns", NetconfigNamespace.NamespaceName),
                new XAttribute(XNamespace.Xmlns + "xsi", InstanceNamespace.NamespaceName),
                new XElement(NetconfigNamespace + "VirtualNetworkConfiguration"));

            var stream = new MemoryStream();
            var writer1 = XmlWriter.Create(stream);
            netConfig.WriteTo(writer1);
            writer1.Flush();
            stream.Seek(0L, SeekOrigin.Begin);

            this.ExecuteClientActionInOCS(null, this.CommandRuntime.ToString(), s => this.Channel.SetNetworkConfiguration(s, stream));
        }
开发者ID:bryanhunter,项目名称:azure-sdk-tools,代码行数:16,代码来源:RemoveAzureVNetConfig.cs

示例12: Write

        public static void Write()
        {
            var xmlConfig = new XElement("Jira",
                                new XElement("ServerUrl", ServerUrl),
                                new XElement("Username", Username),
                                new XElement("Password", Password));

            using (var xmlWriter = XmlWriter.Create(JiraOutput.PrefsPathWithFileName, new XmlWriterSettings()
            {
                Indent = true,
                IndentChars = " "
            }))
            {
                xmlConfig.WriteTo(xmlWriter);
            }
        }
开发者ID:laurentkempe,项目名称:JiraOutput,代码行数:16,代码来源:JiraPreferences.cs

示例13: Main

        static void Main(string[] args)
        {
            //Write XML 1.1 file
            StringBuilder sb = new StringBuilder();
            XmlWriterSettings xws = new XmlWriterSettings();
            xws.Encoding = Encoding.UTF8;
            xws.Indent = true;
            //Disable character checking
            xws.CheckCharacters = false;

            System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(sb, xws);
            //write your own header
            xw.WriteProcessingInstruction("xml", "version='1.1'");
            XElement doc = new XElement("root");
            doc.Add(
                    new XElement("test", 
                            new XAttribute("val", "\x03")));
            //use WriteTo instead of Save
            doc.WriteTo(xw);
            xw.Close();

            //Print XML contents to console
            Console.WriteLine(sb.ToString());
            

            //Read XML 1.1 file
            TextReader tr = new StringReader(sb.ToString());
            tr.ReadLine(); //skip Version number '1.1' is invalid. exception

            XmlReaderSettings xrs = new XmlReaderSettings();
            xrs.CheckCharacters = false;
            XmlReader xr = XmlReader.Create(tr, xrs);

            var xmldoc = XElement.Load(xr);
            foreach (var e in xmldoc.Elements())
            {
                Console.Write("Element: {0}", e.Name);
                foreach (var a in e.Attributes())
                    Console.Write(" Attribute: {0}={1}", a.Name, a.Value);
                Console.WriteLine();
            }
                
        }
开发者ID:kiszu,项目名称:ForBlog,代码行数:43,代码来源:Program.cs

示例14: ParseXml2String

        protected string ParseXml2String(XElement doc)
        {
            using (StringWriter sw = new StringWriter())
            {
                XmlWriterSettings settings = new XmlWriterSettings();
                {
                    settings.OmitXmlDeclaration = true;

                    using (XmlWriter writer = XmlWriter.Create(sw, settings))
                    {
                        if (doc != null)
                        {
                            doc.WriteTo(writer);
                        }
                    }
                }

                return sw.ToString();
            }
        }
开发者ID:jandppw,项目名称:ppwcode-recovered-from-google-code,代码行数:20,代码来源:BaseUserControl.cs

示例15: SerializeXElement

            // ReSharper restore SuggestBaseTypeForParameter
            // ReSharper disable SuggestBaseTypeForParameter
            private static string SerializeXElement(XElement element)
            {
                using (var stringWriter = new StringWriter())
                {
                    var settings = new XmlWriterSettings
                        {
                            Indent = true,
                            IndentChars = "\t",
                            OmitXmlDeclaration = true,
                        };

                    using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter, settings))
                    {
                        element.WriteTo(xmlWriter);
                        xmlWriter.Flush();

                        return stringWriter.ToString();
                    }
                }
            }
开发者ID:nathan-alden,项目名称:old-text-adventure-engine,代码行数:22,代码来源:WorldSerializerTester.cs


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