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


C# XDocument.CreateWriter方法代码示例

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


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

示例1: TransformXML

        public static XDocument TransformXML(XDocument doc, string xslPath)
        {
            XDocument newdoc = new XDocument();

            using (XmlWriter writer = newdoc.CreateWriter())
            {
                // Load the style sheet.
                XslCompiledTransform xslt = new XslCompiledTransform();
                xslt.Load(XmlReader.Create(xslPath));

                // Execute the transform and output the results to a writer.
                xslt.Transform(doc.CreateReader(), writer);
            }

            return newdoc;
            /*
            XslCompiledTransform transform = new XslCompiledTransform();
            using (XmlReader reader = XmlReader.Create(xslPath))
            {
                transform.Load(reader);
            }
            StringWriter results = new StringWriter();
            transform.Transform(doc, null, results);
            var newdoc = new XmlDocument();
            newdoc.LoadXml(results.ToString());
            return newdoc;
             * */
        }
开发者ID:jweisman,项目名称:Exlibris.JiraExtensions,代码行数:28,代码来源:Utilities.cs

示例2: GeneratePlainReport_1

		public void GeneratePlainReport_1()
		{
			ReportModel model = ReportModel.Create();

			ReportStructure reportStructure = new ReportStructure()
			{
				ReportLayout = GlobalEnums.ReportLayout.ListLayout
			};
			IReportGenerator generator = new GeneratePlainReport(model,reportStructure);
			generator.GenerateReport();
			
			XDocument doc1 = XDocument.Load(new XmlNodeReader (generator.XmlReport));
			
			XDocument doc2 = new XDocument();
			
			using (XmlWriter w = doc2.CreateWriter()){
				generator.XmlReport.Save (w);
			}
			XDocument doc3 = ReportGenerationHelper.XmlDocumentToXDocument(generator.XmlReport);
			Assert.IsNotNull (doc1);
			Assert.IsNotNull (doc2);
			Assert.IsNotNull (doc2);
			
			var sq = from si in doc1.Descendants() select si;
			Console.WriteLine ("xxxxx");
			foreach (XElement a in sq)
			{
				Console.WriteLine (a.Name);
			}
			
		}
开发者ID:Rpinski,项目名称:SharpDevelop,代码行数:31,代码来源:GeneratePlainReportFixture_1.cs

示例3: GetXElement

 /// <summary>
 /// Pulled from http://blogs.msdn.com/b/ericwhite/archive/2008/12/22/convert-xelement-to-xmlnode-and-convert-xmlnode-to-xelement.aspx
 /// </summary>
 /// <param name="node"></param>
 /// <returns></returns>
 internal static XElement GetXElement(this XmlNode node)
 {
     XDocument xDoc = new XDocument();
     using (XmlWriter xmlWriter = xDoc.CreateWriter())
         node.WriteTo(xmlWriter);
     return xDoc.Root;
 }
开发者ID:Mavtak,项目名称:WebCommunicator,代码行数:12,代码来源:Utilities.cs

示例4: SerializeConfig

        private void SerializeConfig()
        {
            var extraTypes = new Type[1]{typeof(AbstractConsumer)};

            XDocument doc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
            XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
            namespaces.Add(string.Empty, string.Empty);

            using(var writer = doc.CreateWriter())
            {
                new XmlSerializer(typeof(configuration), extraTypes).Serialize(writer, config, namespaces);
            }

            doc.Element("configuration").Add(
                new XElement("controllers",
                    new XElement("tcp",
                        new XElement[2]
                        {
                            new XElement("port", 5250),
                            new XElement("protocol", "AMCP")
                        })));

            doc.Add(new XComment(CasparCGConfigurator.Properties.Resources.configdoc.ToString()));

            using (var writer = new XmlTextWriter("casparcg.config", new UTF8Encoding(false, false))) // No BOM
            {
                writer.Formatting = Formatting.Indented;
                doc.Save(writer);
            }
        }
开发者ID:erwinmnl,项目名称:Tools,代码行数:30,代码来源:MainForm.cs

示例5: CreateNuspecGraph

        public static IGraph CreateNuspecGraph(XDocument nuspec, string baseAddress)
        {
            nuspec = NormalizeNuspecNamespace(nuspec);

            XslCompiledTransform transform = CreateTransform("xslt.nuspec.xslt");

            XsltArgumentList arguments = new XsltArgumentList();
            arguments.AddParam("base", "", baseAddress + "packages/");
            arguments.AddParam("extension", "", ".json");

            arguments.AddExtensionObject("urn:helper", new XsltHelper());

            XDocument rdfxml = new XDocument();
            using (XmlWriter writer = rdfxml.CreateWriter())
            {
                transform.Transform(nuspec.CreateReader(), arguments, writer);
            }

            RdfXmlParser rdfXmlParser = new RdfXmlParser();
            XmlDocument doc = new XmlDocument();
            doc.Load(rdfxml.CreateReader());
            IGraph graph = new Graph();
            rdfXmlParser.Load(graph, doc);

            return graph;
        }
开发者ID:rvesse,项目名称:NuGet.Services.Metadata,代码行数:26,代码来源:Utils.cs

示例6: GetXElement

 /// <summary>
 /// Provides an extension method that converts an
 /// XmlNode to a Linq XElement.
 /// </summary>
 /// <param name="node">the XmlNode</param>
 /// <returns>Linq XElement</returns>
 public static XElement GetXElement(this XmlNode node)
 {
     var xDoc = new XDocument();
     using (var xmlWriter = xDoc.CreateWriter())
         node.WriteTo(xmlWriter);
     return xDoc.Root;
 }
开发者ID:TimHarrison1260,项目名称:Dissertation,代码行数:13,代码来源:ExtensionMethods.cs

示例7: GetXElement

 private static XElement GetXElement(XmlNode node) {
     var xDoc = new XDocument();
     using (XmlWriter xmlWriter = xDoc.CreateWriter()) {
         node.WriteTo(xmlWriter);
     }
     return xDoc.Root;
 }
开发者ID:radi4music,项目名称:NakedObjectsFramework,代码行数:7,代码来源:NakedObjectsClaimsAuthorizationManager.cs

示例8: GetXElement

 private XElement GetXElement(XmlNode node)
 {
     XDocument xDoc = new XDocument();
     using (XmlWriter xmlWriter = xDoc.CreateWriter())
         node.WriteTo(xmlWriter);
     return xDoc.Root;
 }
开发者ID:gtkrug,项目名称:gfipm-ws-ms.net,代码行数:7,代码来源:WspClaimsAuthorizationManager.cs

示例9: SendBodyAsync

 protected override async Task SendBodyAsync(IRequestContext context)
 {
     if (Xslt != null) {
         if (Model is XDocument)
             await TransformAsync(context, ((XDocument)Model).CreateNavigator());
         else if (Model is IXPathNavigable)
             await TransformAsync(context, ((IXPathNavigable)Model));
         else {
             var ser = Serializer ?? new XmlSerializer(Model.GetType());
             var doc = new XDocument();
             using (var writer = doc.CreateWriter())
                 ser.Serialize(writer, Model);
             await TransformAsync(context, doc.CreateNavigator());
         }
     }
     else {
         using (var writer = context.Response.GetStreamWriter()) {
             if (Model is XDocument)
                 ((XDocument)Model).Save(writer);
             else if (Model is XmlDocument)
                 ((XmlDocument)Model).Save(writer);
             else if (Model is IXPathNavigable)
                 using (var xWriter = new XmlTextWriter(writer))
                     ((IXPathNavigable)Model).CreateNavigator().WriteSubtree(xWriter);
             else
                 (Serializer ?? new XmlSerializer(Model.GetType()))
                     .Serialize(writer, Model);
         }
     }
 }
开发者ID:jammycakes,项目名称:dolstagis.web,代码行数:30,代码来源:XmlResult.cs

示例10: Initialize

        public override void Initialize()
        {
            base.Initialize();

            List<Notice> list = new List<Notice>();

            list.Add(new Notice() { Year = 1972, News = "PLATO IV: First computer with \n a touchable screen." });
            list.Add(new Notice() { Year = 1985, News = "Home Manager: First home computer \n with a touchable screen." });
            list.Add(new Notice() { Year = 1992, News = "SIMON. First smartphone." });
            list.Add(new Notice() { Year = 1999, News = "Edge: Voting machine." });
            list.Add(new Notice() { Year = 2000, News = "iPhone: Firts multitouch smartphone." });

            XDocument doc = new XDocument();
            XmlSerializer serializer = new XmlSerializer(typeof(List<Notice>));
            System.Xml.XmlWriter writer = doc.CreateWriter();
            serializer.Serialize(writer, list);
            writer.Close();
            IsolatedStorage.SaveFile(doc, "myFile");

            btGetNotice = new Button("Get next notice");
            btGetNotice.Released += new Component.ComponentEventHandler(btnOpenBox_Released);
            AddComponent(btGetNotice, 50, 600);

            lblTime = new Label(list[0].Year.ToString());
            lblNotice = new Label(list[0].News);
            AddComponent(lblTime, 50, 100);
            AddComponent(lblNotice, 50, 200);
            index = 1;
        }
开发者ID:Syderis,项目名称:CellSDK-Tutorials,代码行数:29,代码来源:MainScreen.cs

示例11: Serialize

        /// <summary>
        /// Serializes the specified ParticleEffect instance.
        /// </summary>
        /// <param name="effect">The ParticleEffect to be serialized.</param>
        /// <param name="filename">The desired output file name,</param>
        public void Serialize(ParticleEffect effect, string filename)
        {
            // Create a new xml document...
            XDocument xmlDocument = new XDocument();

            // Use the XNA serializer to populate the xml document...
            using (XmlWriter writer = xmlDocument.CreateWriter())
            {
                IntermediateSerializer.Serialize<ParticleEffect>(writer, effect, ".\\");
            }

            //// hack: Workaround for intermediate serializer not putting nodes in the right order...
            //foreach (XElement emitterElement in xmlDocument.Descendants("Asset").Elements("Item"))
            //{
            //    XElement releaseQuantityElement = emitterElement.Element("ReleaseQuantity");

            //    if ((releaseQuantityElement.PreviousNode as XElement).Name == "Name")
            //    {
            //        XElement termElement = emitterElement.Element("Term");

            //        termElement.AddAfterSelf(releaseQuantityElement);

            //        releaseQuantityElement.Remove();
            //    }
            //}

            // Save the xml document...
            xmlDocument.Save(filename);
        }
开发者ID:Andrea,项目名称:MercuryParticleEngine,代码行数:34,代码来源:DefaultEffectSerializationPlugin.cs

示例12: ReadWrite

        public void ReadWrite()
        {
            var person = new Person() { Name = "duraid", Age = 35 };
            person.Addresses.Add(new Address() { Street = "Decelles", City = "Montreal" });
            person.Addresses.Add(new Address() { Street = "Lincoln", City = "Montreal" });
            var map = new PersonMap();

            var doc = new XDocument();
            
            using (var writer = doc.CreateWriter())
            {
                map.WriteXml(writer, person);
            }

            Person person2;
            using (var reader = doc.CreateReader())
            {
                person2 = map.ReadXml(reader);
            }

            Assert.AreEqual(person.Name, person2.Name);
            Assert.AreEqual(person.Age, person2.Age);
            Assert.AreEqual(2, person.Addresses.Count);
            person.Addresses.Where(a => a.Street == "Decelles" && a.City == "Montreal").Single();
            person.Addresses.Where(a => a.Street == "Lincoln" && a.City == "Montreal").Single();
        }
开发者ID:dur41d,项目名称:sdmxdotnet,代码行数:26,代码来源:PersonMapTests.cs

示例13: GetPersonInfo

        public Stream GetPersonInfo(string id)
        {
            int personId = 0;
            int.TryParse(id, out personId);
            Person personFound = persons.FirstOrDefault(p => p.Id == personId);

            if (WebOperationContext.Current != null)
                WebOperationContext.Current.OutgoingResponse.ContentType = "text/html";

            var reader = new StringReader(Resource.Style);
            XmlReader xreader = XmlReader.Create(reader);
            var xslt = new XslCompiledTransform(false);
            xslt.Load(xreader);
            var serializer = new XmlSerializer(typeof(Person));

            var doc = new XDocument();
            using (XmlWriter writer = doc.CreateWriter())
            {
                if (personFound != null) 
                    serializer.Serialize(writer, personFound);
            }

            var outputWriter = new StringWriter();
            xslt.Transform(doc.CreateNavigator(), null, outputWriter);
            string htmlEmailText = outputWriter.ToString();

            var encoding = new System.Text.ASCIIEncoding();
            var stream = new MemoryStream(encoding.GetBytes(htmlEmailText));

            return stream;
        }
开发者ID:modulexcite,项目名称:Quartz.net.James,代码行数:31,代码来源:CoolService.svc.cs

示例14: PerformAnotherWordGrammarDebuggerStepPage

		/// <summary>
		/// Perform another step in the word grammar debugging process and
		/// produce an html page showing the results
		/// </summary>
		/// <param name="nodeId">Id of the selected node to use</param>
		/// <param name="form"></param>
		/// <param name="lastUrl"></param>
		/// <returns>temporary html file showing the results of the next step</returns>
		public string PerformAnotherWordGrammarDebuggerStepPage(string nodeId, string form, string lastUrl)
		{
			m_xmlHtmlStack.Push(Tuple.Create(m_wordGrammarDebuggerXml, lastUrl));
			var doc = new XDocument();
			using (XmlWriter writer = doc.CreateWriter())
				CreateSelectedWordGrammarXml(writer, nodeId, form);
			return CreateWordDebuggerPage(doc);
		}
开发者ID:bbriggs,项目名称:FieldWorks,代码行数:16,代码来源:WordGrammarDebugger.cs

示例15: SetUpWordGrammarDebuggerPage

		/// <summary>
		/// Initialize what is needed to perform the word grammar debugging and
		/// produce an html page showing the results
		/// </summary>
		/// <param name="nodeId">Id of the node to use</param>
		/// <param name="form">the wordform being tried</param>
		/// <param name="lastUrl"></param>
		/// <returns>temporary html file showing the results of the first step</returns>
		public string SetUpWordGrammarDebuggerPage(string nodeId, string form, string lastUrl)
		{
			m_xmlHtmlStack.Push(Tuple.Create((XDocument) null, lastUrl));
			var doc = new XDocument();
			using (XmlWriter writer = doc.CreateWriter())
				CreateAnalysisXml(writer, nodeId, form);
			return CreateWordDebuggerPage(doc);
		}
开发者ID:bbriggs,项目名称:FieldWorks,代码行数:16,代码来源:WordGrammarDebugger.cs


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