Esempio n. 1
0
        // --------------------------------------------------------------------------------------------------------------
        //  LoadXSL_Resolver
        //  -------------------------------------------------------------------------------------------------------------
        public int LoadXSL_Resolver(String _strXslFile, XmlResolver xr)
        {
            _strXslFile = FullFilePath(_strXslFile);
            xslt = new XslCompiledTransform();
            XmlReaderSettings xrs = null;
            switch (_nInputXsl)
            {
                case XslInputType.URI:
                    _output.WriteLine("Loading style sheet as URI " + _strXslFile);
                    xslt.Load(_strXslFile, XsltSettings.TrustedXslt, xr);
                    break;

                case XslInputType.Reader:
                    switch (_readerType)
                    {
                        case ReaderType.XmlTextReader:
                            XmlTextReader trTemp = new XmlTextReader(_strXslFile);
                            try
                            {
                                _output.WriteLine("Loading style sheet as XmlTextReader " + _strXslFile);
                                xslt.Load(trTemp, XsltSettings.TrustedXslt, xr);
                            }
                            catch (Exception ex)
                            {
                                throw (ex);
                            }
                            finally
                            {
                                if (trTemp != null)
                                    trTemp.Dispose();
                            }
                            break;

                        case ReaderType.XmlNodeReader:
                            XmlDocument docTemp = new XmlDocument();
                            docTemp.Load(_strXslFile);
                            XmlNodeReader nrTemp = new XmlNodeReader(docTemp);
                            try
                            {
                                _output.WriteLine("Loading style sheet as XmlNodeReader " + _strXslFile);
                                xslt.Load(nrTemp, XsltSettings.TrustedXslt, xr);
                            }
                            catch (Exception ex)
                            {
                                throw (ex);
                            }
                            finally
                            {
                                if (nrTemp != null)
                                    nrTemp.Dispose();
                            }
                            break;

                        case ReaderType.XmlValidatingReader:
                        default:
                            xrs = new XmlReaderSettings();
#pragma warning disable 0618
                            xrs.ProhibitDtd = false;
#pragma warning restore 0618
                            XmlReader vrTemp = XmlReader.Create(_strXslFile, xrs);
                            try
                            {
                                _output.WriteLine("Loading style sheet as XmlValidatingReader " + _strXslFile);
                                xslt.Load(vrTemp, XsltSettings.TrustedXslt, xr);
                            }
                            catch (Exception ex)
                            {
                                throw (ex);
                            }
                            finally
                            {
                                if (vrTemp != null)
                                    vrTemp.Dispose();
                            }
                            break;
                    }
                    break;

                case XslInputType.Navigator:
                    xrs = new XmlReaderSettings();
#pragma warning disable 0618
                    xrs.ProhibitDtd = false;
#pragma warning restore 0618
                    XmlReader xrLoad = XmlReader.Create(_strXslFile, xrs);

                    XPathDocument xdTemp = new XPathDocument(xrLoad, XmlSpace.Preserve);
                    xrLoad.Dispose();
                    _output.WriteLine("Loading style sheet as Navigator " + _strXslFile);
                    xslt.Load(xdTemp, XsltSettings.TrustedXslt, xr);
                    break;
            }
            return 1;
        }
Esempio n. 2
0
        // --------------------------------------------------------------------------------------------------------------
        //  LoadXSL_Resolver
        //  -------------------------------------------------------------------------------------------------------------
        public int LoadXSL_Resolver(String _strXslFile, XmlResolver xr)
        {
            _strXslFile = FullFilePath(_strXslFile);
#pragma warning disable 0618
            xslt = new XslTransform();
#pragma warning restore 0618

            switch (_nInput)
            {
                case InputType.URI:
                    _output.WriteLine("Loading style sheet as URI {0}", _strXslFile);
                    xslt.Load(_strXslFile, xr);
                    break;

                case InputType.Reader:
                    switch (_readerType)
                    {
                        case ReaderType.XmlTextReader:
                            XmlTextReader trTemp = new XmlTextReader(_strXslFile);
                            try
                            {
                                _output.WriteLine("Loading style sheet as XmlTextReader {0}", _strXslFile);
                                xslt.Load(trTemp, xr);
                            }
                            catch (Exception ex)
                            {
                                throw (ex);
                            }
                            finally
                            {
                                if (trTemp != null)
                                    trTemp.Dispose();
                            }
                            break;

                        case ReaderType.XmlNodeReader:
                            XmlDocument docTemp = new XmlDocument();
                            docTemp.Load(_strXslFile);
                            XmlNodeReader nrTemp = new XmlNodeReader(docTemp);
                            try
                            {
                                _output.WriteLine("Loading style sheet as XmlNodeReader {0}", _strXslFile);
                                xslt.Load(nrTemp, xr);
                            }
                            catch (Exception ex)
                            {
                                throw (ex);
                            }
                            finally
                            {
                                if (nrTemp != null)
                                    nrTemp.Dispose();
                            }
                            break;

                        case ReaderType.XmlValidatingReader:
                        default:
#pragma warning disable 0618
                            XmlValidatingReader vrTemp = new XmlValidatingReader(new XmlTextReader(_strXslFile));
#pragma warning restore 0618
                            vrTemp.ValidationType = ValidationType.None;
                            vrTemp.EntityHandling = EntityHandling.ExpandEntities;
                            try
                            {
                                _output.WriteLine("Loading style sheet as XmlValidatingReader {0}", _strXslFile);
                                xslt.Load(vrTemp, xr);
                            }
                            catch (Exception ex)
                            {
                                throw (ex);
                            }
                            finally
                            {
                                if (vrTemp != null)
                                    vrTemp.Dispose();
                            }
                            break;
                    }
                    break;

                case InputType.Navigator:
#pragma warning disable 0618
                    XmlValidatingReader xrLoad = new XmlValidatingReader(new XmlTextReader(_strXslFile));
#pragma warning restore 0618
                    XPathDocument xdTemp = new XPathDocument(xrLoad, XmlSpace.Preserve);
                    xrLoad.Dispose();
                    _output.WriteLine("Loading style sheet as Navigator {0}", _strXslFile);
                    xslt.Load(xdTemp, xr);
                    break;
            }
            return 1;
        }