コード例 #1
0
        internal static XslCompiledTransform CachedXslt(string filename, bool UseXSL)
        {
            XslCompiledTransform result   = new XslCompiledTransform(true);
            XsltSettings         settings = new XsltSettings(true, true);
            SPXmlUrlResolver     resolver = new SPXmlUrlResolver();

            resolver.Credentials = CredentialCache.DefaultNetworkCredentials;

            XmlReaderSettings readerSettings = new XmlReaderSettings();

            readerSettings.ValidationFlags = System.Xml.Schema.XmlSchemaValidationFlags.None;
            readerSettings.XmlResolver     = resolver;
            readerSettings.DtdProcessing   = DtdProcessing.Ignore;
            //readerSettings.ProhibitDtd = false;
            readerSettings.CheckCharacters = false;

            if (filename != null)
            {
                SPFile file = SPContext.Current.Site.RootWeb.GetFile(filename);

                using (XmlReader reader = XmlReader.Create(file.OpenBinaryStream(SPOpenBinaryOptions.None), readerSettings))//, SPContext.Current.Site.RootWeb.Url))
                {
                    result.Load(reader, settings, resolver);
                }
            }

            return(result);
        }
コード例 #2
0
        internal static XslCompiledTransform CachedXslt(string xslsource)
        {
            XslCompiledTransform result   = new XslCompiledTransform(true);
            XsltSettings         settings = new XsltSettings(true, true);
            SPXmlUrlResolver     resolver = new SPXmlUrlResolver();

            resolver.Credentials = CredentialCache.DefaultNetworkCredentials;

            XmlReaderSettings readerSettings = new XmlReaderSettings();

            readerSettings.ValidationFlags = System.Xml.Schema.XmlSchemaValidationFlags.None;
            readerSettings.XmlResolver     = resolver;
            readerSettings.DtdProcessing   = DtdProcessing.Ignore;
            //readerSettings.ProhibitDtd = false;
            readerSettings.CheckCharacters = false;

            MemoryStream stream = new MemoryStream();
            StreamWriter writer = new StreamWriter(stream);

            writer.Write(xslsource);
            writer.Flush();
            stream.Position = 0L;


            using (XmlReader reader = XmlReader.Create(stream, readerSettings))//, SPContext.Current.Site.RootWeb.Url))
            {
                try
                {
                    result.Load(reader, settings, resolver);
                }
                catch (XsltException)
                {
                    throw;
                }
            }

            return(result);
        }