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


C# XmlWriterSettings.GetType方法代碼示例

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


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

示例1: Transform

        public static string Transform( string xmlPath, XsltArgumentList argList )
        {
            string html = null;

            try
            {
                string transformFile = RulesEngineUtils.GetResourcePath( RulesEngineUtils.ReportBuilderFolder.Resources, "InstanceReport.xslt" );

                XslCompiledTransform transform = new XslCompiledTransform();
                transform.Load( transformFile );

                using( MemoryStream ms = new MemoryStream() )
                {
                    XmlWriterSettings xSettings = new XmlWriterSettings();
                    xSettings.ConformanceLevel = ConformanceLevel.Fragment;
                    xSettings.Encoding = Encoding.ASCII;
                    xSettings.Indent = true;
                    xSettings.OmitXmlDeclaration = true;

                    //we REALLY need to set this to HTML
                    xSettings.GetType().GetProperty( "OutputMethod" ).SetValue( xSettings, XmlOutputMethod.Html, null );

                    using( XmlWriter xWriter = XmlWriter.Create( ms, xSettings ) )
                    {
                        transform.Transform( xmlPath, argList, xWriter );
                    }

                    ms.Flush();
                    html = Encoding.ASCII.GetString( ms.ToArray() );
                }
            }
            catch( Exception ex )
            {
                html = "<h2>Error <small>generating preview</small></h2>"+
                    "<pre>"+ ex.Message +"</pre>";
            }

            return html;
        }
開發者ID:plamikcho,項目名稱:xbrlpoc,代碼行數:39,代碼來源:Test_Abstract.cs

示例2: GenerateHtmlFiles

        /// <summary>
        /// Generates HTML report files if allowed by this.<see cref="ReportFormat"/> and as specified by this.<see cref="HtmlReportFormat"/>.
        /// </summary>
        /// <returns>True on success, false on fail.</returns>
        private bool GenerateHtmlFiles()
        {
            // Use custom XSLT if provided
            string transformFile = String.Empty;
            if (!String.IsNullOrEmpty(this.xsltStylesheetPath))
            {
                //executor.Invoke(this.xsltStylesheetPath);
                transformFile = this.xsltStylesheetPath;
            }
            else
            {
                transformFile = RulesEngineUtils.GetResourcePath( RulesEngineUtils.ReportBuilderFolder.Resources, RulesEngineUtils.TransformFile );
                //executor.Invoke(transformFile);
            }

            if( !File.Exists( transformFile ) )
            {
                executor.Invoke("Conversion aborted");
                Trace.TraceError( "Error: Transform File not found at:\n\t" + transformFile + "\nHtml Conversion aborted." );
                return false;
            }

            bool anyFiles = false;

            //load the transform once for all R-files
            XslCompiledTransform transform = new XslCompiledTransform();
            try
            {
                transform.Load(transformFile);
            }
            catch ( XmlException )
            {
                Trace.TraceError("Error: Transform File contains invalid XML:\n\t" + transformFile + "\nHtml Conversion aborted.");
                return false;
            }
            catch ( XsltException )
            {
                Trace.TraceError("Error: Transform File contains invalid XSLT:\n\t" + transformFile + "\nHtml Conversion aborted.");
                return false;
            }

            XsltArgumentList argList = new XsltArgumentList();
            argList.Clear();

            if( this.HtmlReportFormat == HtmlReportFormat.Complete )
            {
                argList.AddParam( "asPage", string.Empty, "true" );

            }

            argList.AddParam( "numberDecimalSeparator", string.Empty, Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator );
            argList.AddParam( "numberGroupSeparator", string.Empty, Thread.CurrentThread.CurrentCulture.NumberFormat.NumberGroupSeparator );
            argList.AddParam( "numberGroupSize", string.Empty, Thread.CurrentThread.CurrentCulture.NumberFormat.NumberGroupSizes[ 0 ].ToString() );

            XmlWriterSettings writerSettings = new XmlWriterSettings();
            writerSettings.Encoding = InstanceReport.Encoding;
            writerSettings.Indent = true;
            writerSettings.OmitXmlDeclaration = true;

            //set intelligent HTML output
            writerSettings.GetType().GetProperty( "OutputMethod" ).SetValue( writerSettings, XmlOutputMethod.Html, null );

            foreach( ReportHeader header in this.currentFilingSummary.MyReports )
            {
                switch( header.ReportType )
                {
                    case ReportHeaderType.Notes:
                    case ReportHeaderType.Sheet:
                        break;
                    default:
                        continue;
                }

                string inFile = Path.Combine( this.currentReportDirectory, header.XmlFileName );
                if( !File.Exists( inFile ) )
                {
                    Trace.TraceWarning( "Warning: The FilingSummary provided '"+ header.XmlFileName +"' but the file was not found." +
                        separator +"\tReport skipped: "+ header.LongName );
                    continue;
                }

                int extLen = Path.GetExtension( header.XmlFileName ).Length;
                string outFile = inFile.Substring( 0, inFile.Length - extLen ) +".htm";

                using( XmlReader xReader = XmlReader.Create( inFile ) )
                {
                    using( FileStream msOut = new FileStream( outFile, FileMode.Create, FileAccess.Write ) )
                    {
                        try
                        {
                            using( RivetXmlWriter xWriter = new RivetXmlWriter( msOut, writerSettings ) )
                            {
                                transform.Transform( xReader, argList, xWriter );
                            }

                            anyFiles = true;
//.........這裏部分代碼省略.........
開發者ID:plamikcho,項目名稱:xbrlpoc,代碼行數:101,代碼來源:ReportBuilder.cs


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