當前位置: 首頁>>代碼示例>>C#>>正文


C# XElement.CreateReader方法代碼示例

本文整理匯總了C#中System.Xml.Linq.XElement.CreateReader方法的典型用法代碼示例。如果您正苦於以下問題:C# XElement.CreateReader方法的具體用法?C# XElement.CreateReader怎麽用?C# XElement.CreateReader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Xml.Linq.XElement的用法示例。


在下文中一共展示了XElement.CreateReader方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: GetRedirectList

        private static AssemblyBinding GetRedirectList(XElement element)
        {
            var serializer = new XmlSerializer(typeof(AssemblyBinding));
            if (!serializer.CanDeserialize(element.CreateReader()))
            {
                Error("Unable to deserialize assembly bindings, please ensure xml is valid", true);

                return null;
            }

            return serializer.Deserialize(element.CreateReader()) as AssemblyBinding;
        }
開發者ID:TCBroad,項目名稱:BindingCleaner,代碼行數:12,代碼來源:Program.cs

示例2: Xml2Html

        /// <summary>
        ///將xml轉化為html;
        ///應用命名空間:
        /// using System.Xml;
        /// using System.Xml.XPath;
        /// using System.Xml.Xsl;
        /// </summary>
        /// <param name="xmlDocument">XDocument對象</param>
        /// <param name="xslFileStream">xsl數據流</param>
        /// <param name="htmlFilePath">輸出路徑</param>
        /// <returns>Exception</returns>
        public static Exception Xml2Html(XElement xmlDocument, TextReader xslFileStream, string htmlFilePath)
        {
            Exception SuFlag = new Exception("操作成功");
            try
            {
                //生成Html文件路徑
                string HtmlFilePath = htmlFilePath;
                XmlReader xst = XmlReader.Create(xslFileStream, new XmlReaderSettings() { DtdProcessing = DtdProcessing.Ignore});

                XmlReader xmlreader = xmlDocument.CreateReader(ReaderOptions.OmitDuplicateNamespaces);

                XPathDocument myXPathDoc = new XPathDocument(xmlreader);
                XslCompiledTransform myXslTrans = new XslCompiledTransform();

                xmlreader.Close();
                //加載XSL文件
                XsltSettings xs = XsltSettings.TrustedXslt;
                myXslTrans.Load(xst, xs, new XmlUrlResolver());

                XmlWriter myWriter = XmlTextWriter.Create(HtmlFilePath, myXslTrans.OutputSettings);
                myXslTrans.Transform(myXPathDoc, null, myWriter);
                myWriter.Close();
                xst.Close();
            }
            catch (Exception ex)
            {
                SuFlag = ex;
            }
            return SuFlag;
        }
開發者ID:J8mao,項目名稱:NazicpUtils,代碼行數:41,代碼來源:Nazicp.Xml.cs

示例3: XElement

        public void LineNumber_and_LinePosition_return_line_and_column_number_for_text_if_XNodeReader_positioned_on_text_node()
        {
            var inputXml = new XElement("dummy", "value");

            var mockModelProvider = new Mock<XmlModelProvider>();
            mockModelProvider
                .Setup(m => m.GetTextSpanForXObject(It.Is<XObject>(x => x == inputXml.FirstNode), It.IsAny<Uri>()))
                .Returns(new TextSpan { iStartLine = 21, iStartIndex = 42, });

            using (var reader = inputXml.CreateReader())
            {
                reader.Read();
                reader.Read();
                Assert.Equal(XmlNodeType.Text, reader.NodeType);
                Assert.Equal("value", reader.Value);

                using (var modelProvider = mockModelProvider.Object)
                {
                    Assert.Equal(
                        21,
                        new XNodeReaderLineNumberService(modelProvider, reader, new Uri("urn:abc")).LineNumber);

                    Assert.Equal(
                        42,
                        new XNodeReaderLineNumberService(modelProvider, reader, new Uri("urn:abc")).LinePosition);
                }
            }
        }
開發者ID:Cireson,項目名稱:EntityFramework6,代碼行數:28,代碼來源:XNodeReaderLineNumberServiceTests.cs

示例4: CreateXmlReader

 private static XmlReader CreateXmlReader(EFArtifact artifact, XElement xobject)
 {
     var baseReader = xobject.CreateReader();
     var lineNumberService = new XNodeReaderLineNumberService(artifact.XmlModelProvider, baseReader, artifact.Uri);
     var proxyReader = new XmlReaderProxy(baseReader, artifact.Uri, lineNumberService);
     return proxyReader;
 }
開發者ID:Cireson,項目名稱:EntityFramework6,代碼行數:7,代碼來源:LegacyCodeGenerationDriver.cs

示例5: Load

		/// <summary>
		/// Converts source XML with given transform with applying DSL
		/// </summary>
		/// <param name="xml"> </param>
		/// <returns>XElement with data, converted by transform</returns>
		/// <exception cref="XmlDslLoaderException">
		/// <list type="bullet">
		/// <item><description>cannot find transform file</description></item>
		/// <item><description>any problem with underlined XmlDslDefinition</description></item>
		/// </list>
		/// </exception>
		public XElement Load(XElement xml) {
			if (null == xml.Element("transform")) return xml; //no dsl needed
			var trdef = new XmlDslDefinition().Extract(xml);
			var langfile = Resolver.Resolve(Rootdir+"/" + trdef.LangName + ".xslt", false);
			if (!File.Exists(langfile))
			{
				throw new XmlDslLoaderException("Не возможно найти файл XML языка" + langfile);
			}
			var xsl = new XslCompiledTransform();
			if(trdef.NeedPrepareXslt) {
				var xsltcontent = XElement.Load(langfile);
				xsltcontent = trdef.PrepareXslt(xsltcontent);
				var resolver = new XmlDslRootBasedXmlUrlResolver(langfile);
				xsl.Load(xsltcontent.CreateReader(),XsltSettings.TrustedXslt,resolver);
			}else {
				xsl.Load(langfile, XsltSettings.TrustedXslt, new XmlUrlResolver());
			}
			var args = trdef.CreateArguments();
			var sw = new StringWriter();
			using (var xw = XmlWriter.Create(sw)) {
				xsl.Transform(xml.CreateReader(),args,xw);
				xw.Flush();
			}
			return XElement.Parse(sw.ToString());
		}
開發者ID:Qorpent,項目名稱:comdiv.oldcore,代碼行數:36,代碼來源:XmlDslLoader.cs

示例6: Create

        private static StorageException Create(int httpStatusCode, XElement extendedErrorElement)
        {
            // Unfortunately, the RequestResult properties are all internal-only settable. ReadXml is the only way to
            // create a populated RequestResult instance.
            XElement requestResultElement = new XElement("RequestResult",
                new XElement("HTTPStatusCode", httpStatusCode),
                new XElement("HttpStatusMessage"),
                new XElement("TargetLocation"),
                new XElement("ServiceRequestID"),
                new XElement("ContentMd5"),
                new XElement("Etag"),
                new XElement("RequestDate"),
                new XElement("StartTime", DateTime.Now),
                new XElement("EndTime", DateTime.Now),
                extendedErrorElement);

            RequestResult result = new RequestResult();

            using (XmlReader reader = requestResultElement.CreateReader())
            {
                result.ReadXml(reader);
            }

            return new StorageException(result, null, null);
        }
開發者ID:ConnorMcMahon,項目名稱:azure-webjobs-sdk,代碼行數:25,代碼來源:StorageExceptionFactory.cs

示例7: GetType

        /// <summary>
        /// Converts an object into its XML representation.
        /// </summary>
        /// <param name="writer">The <see cref="T:System.Xml.XmlWriter"/> stream to which the object is serialized.</param>
        void IXmlSerializable.WriteXml(XmlWriter writer)
        {
            var type = GetType();

            var element = new XElement(type.Name);
            var serializer = SerializationFactory.GetXmlSerializer();
            serializer.Serialize(this, new XmlSerializationContextInfo(element, this));

            // The serializer gives us the full element, but we only need the actual content. According to
            // http://stackoverflow.com/questions/3793/best-way-to-get-innerxml-of-an-xelement, this method is the fastest:
            var reader = element.CreateReader();
            reader.MoveToContent();

            // CTL-710: fix attributes on top level elements
            if (reader.HasAttributes)
            {
                for (int i = 0; i < reader.AttributeCount; i++)
                {
                    reader.MoveToAttribute(i);

                    var attributePrefix = reader.Prefix;
                    var attributeLocalName = reader.LocalName;
                    var attributeNs = reader.NamespaceURI;
                    var attributeValue = reader.Value;

                    writer.WriteAttributeString(attributePrefix, attributeLocalName, attributeNs, attributeValue);
                }

                reader.MoveToElement();
            }

            var elementContent = reader.ReadInnerXml();

            writer.WriteRaw(elementContent);
        }
開發者ID:matthijskoopman,項目名稱:Catel,代碼行數:39,代碼來源:ModelBase.serialization.xml.cs

示例8: When_transforming_xml_to_html_output_is_generated

 public void When_transforming_xml_to_html_output_is_generated()
 {
     XElement element = new XElement("ApiCheckResult");
       MemoryStream sut = new MemoryStream();
       Assert.DoesNotThrow(() => XmlTransformer.TransformToHtml(element.CreateReader(), sut));
       Assert.Greater(sut.Length, 0);
 }
開發者ID:gitter-badger,項目名稱:ApiCheck,代碼行數:7,代碼來源:XmlTransformerTest.cs

示例9: Create

 /// <summary>
 /// Creates the specified path to config file.
 /// </summary>
 /// <param name="sectionElement">The section element.</param>
 /// <returns>The strongly typed consfig section</returns>
 private object Create(XElement sectionElement)
 {
     var typeName = sectionElement.HasAttributes ? sectionElement.Attributes()
                                                     .SingleOrDefault(x => x.Name.LocalName.Equals("Type", StringComparison.InvariantCultureIgnoreCase)).Value
                                                     : string.Empty;
     var ser = new XmlSerializer(Type.GetType(typeName));
     return ser.Deserialize(sectionElement.CreateReader());
 }
開發者ID:Molibar,項目名稱:Molibar.Framework,代碼行數:13,代碼來源:XmlSerializerSectionHandler.cs

示例10: ConvertToErrorHtml

	    private string ConvertToErrorHtml(XElement xml) {
	        var xslt = GetType().Assembly.ReadManifestResource("errors.xslt");
	        var cxslt = new XslCompiledTransform();
            cxslt.Load(XmlReader.Create(new StringReader(xslt)),XsltSettings.TrustedXslt, new XmlUrlResolver());
	        var sw = new StringWriter();
            cxslt.Transform(xml.CreateReader(),new XsltArgumentList(),sw);
	        return sw.ToString();
	    }
開發者ID:Qorpent,項目名稱:qorpent.integration,代碼行數:8,代碼來源:WriteErrorInfoTask.cs

示例11: GetXmlNode

		static XmlNode GetXmlNode(XElement element)
		{
			using (XmlReader xmlReader = element.CreateReader())
			{
				var xmlDoc = new XmlDocument();
				xmlDoc.Load(xmlReader);
				return xmlDoc;
			}
		}
開發者ID:JustAndrei,項目名稱:C1-Packages,代碼行數:9,代碼來源:TellAFriend.asmx.cs

示例12: GetXmlNamespaceManager

        public static XmlNamespaceManager GetXmlNamespaceManager(XElement elem)
        {
            XmlNamespaceManager xnsm = new XmlNamespaceManager(elem.CreateReader().NameTable);
            foreach (var key in TypeNamespaces.AllKeys) {
                xnsm.AddNamespace(TypeNamespaces[key], key);
            }

            return xnsm;
        }
開發者ID:Terradue,項目名稱:DotNetElasticCas,代碼行數:9,代碼來源:DefaultNamespaces.cs

示例13: Expression

 public static IExpression Expression(this IExpressionsManager manager, XElement element)
 {
     Configuration config = new Configuration();
     IConfigurationElement configElement = config.AddSection("expression extensions").AddElement("expression");
     configElement.ReadXml(element.CreateReader());
     IExpression expression = manager.Token(configElement.GetAttributeReference("type").Value.ToString()) as IExpression;
     if (null != expression)
         expression.Make(configElement, manager);
     return expression;
 }
開發者ID:t1b1c,項目名稱:lwas,代碼行數:10,代碼來源:XmlExtensions.cs

示例14: Execute

 private void Execute(XslCompiledTransform xslt, XElement xml, XsltArgumentList args, string path) {
     Directory.CreateDirectory(Path.GetDirectoryName(path));
     if (NoXml)
     {
         using (var tw = new StreamWriter(path))
         {
             xslt.Transform(xml.CreateReader(),args,tw);
             tw.Flush();
         }
     }
     else
     {
         using (var xw = XmlWriter.Create(path))
         {
             xslt.Transform(xml.CreateReader(), args, xw, new BSharpXmlResolver(Project));
             xw.Flush();
         }
     }
 }
開發者ID:Qorpent,項目名稱:qorpent.sys,代碼行數:19,代碼來源:XsltTask.cs

示例15: DownCastToSurfaceElement

 private static XmlElement DownCastToSurfaceElement(XElement element)
 {
     XNamespace ns = "http://www.opengis.net/gml/3.2";
     XmlDocument doc = new XmlDocument();
   
     element.Name = ns+ "Surface";         
     
     return doc.ReadNode(element.CreateReader()) as XmlElement;
    
 }
開發者ID:s-innovations,項目名稱:S-Innovations.Aixm,代碼行數:10,代碼來源:AIXMElevatedSurfaceConverter.cs


注:本文中的System.Xml.Linq.XElement.CreateReader方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。