예제 #1
0
    public bool Load(string strFileName)
    {
#pragma warning disable 0618
        XmlTextReader       rXmlTextReader;
        XmlValidatingReader rXmlValidatingReader;
        bool fRet;

        rXmlTextReader = new XmlTextReader(strFileName);
        rXmlTextReader.WhitespaceHandling = _eWhitespaceMode;
        rXmlTextReader.Namespaces         = _fNamespaces;

        _eEncoding = rXmlTextReader.Encoding;

        rXmlValidatingReader = new XmlValidatingReader(rXmlTextReader);
        rXmlValidatingReader.ValidationType = _eValidationMode;
        rXmlValidatingReader.EntityHandling = _eEntityMode;
#pragma warning restore 0618

        if (_fValidationCallback)
        {
            rXmlValidatingReader.ValidationEventHandler += new ValidationEventHandler(this.ValidationCallback);
        }

        try
        {
            fRet = Load((XmlReader)rXmlValidatingReader);
        }
        catch (Exception e)
        {
            fRet = false;
            rXmlValidatingReader.Dispose();
            rXmlTextReader.Dispose();

            if (_strParseError == string.Empty)
            {
                _strParseError = e.ToString();
            }

            if (_fThrow)
            {
                throw (e);
            }
        }

        rXmlValidatingReader.Dispose();
        rXmlTextReader.Dispose();
        return(fRet);
    }
예제 #2
0
        ////////////////////////////////////////////////////////////////
        // Same instance testing:
        // Multiple Transform() using shared ArgumentList
        ////////////////////////////////////////////////////////////////
        public int SharedArgList(object args)
        {
            string _strXslFile = ((object[])args)[1].ToString();
            string _strXmlFile = ((object[])args)[2].ToString();

            if (_strXslFile.Substring(0, 5) != "http:")
            {
                _strXslFile = Path.Combine(_strPath, _strXslFile);
            }
            if (_strXmlFile.Substring(0, 5) != "http:")
            {
                _strXmlFile = Path.Combine(_strPath, _strXmlFile);
            }

#pragma warning disable 0618
            XmlValidatingReader xrData = new XmlValidatingReader(new XmlTextReader(_strXmlFile));
            XPathDocument       xd     = new XPathDocument(xrData, XmlSpace.Preserve);
            xrData.Dispose();

            XslTransform        xslt   = new XslTransform();
            XmlValidatingReader xrTemp = new XmlValidatingReader(new XmlTextReader(_strXslFile));
#pragma warning restore 0618
            xrTemp.ValidationType = ValidationType.None;
            xrTemp.EntityHandling = EntityHandling.ExpandCharEntities;
            xslt.Load(xrTemp);

            XmlReader xrXSLT = null;

            for (int i = 1; i <= 100; i++)
            {
                xrXSLT = xslt.Transform(xd, xsltArg1);
                _output.WriteLine("SharedArgumentList: Thread " + ((object[])args)[0] + "\tIteration " + i + "\tDone with transform...");
            }
            return(1);
        }
예제 #3
0
        protected override void Load(string _strXslFile, string _strXmlFile)
        {
#pragma warning disable 0618
            XmlValidatingReader xrData = new XmlValidatingReader(new XmlTextReader(Path.Combine(_strPath, _strXmlFile)));
#pragma warning restore 0618
            _xd = new XPathDocument(xrData, XmlSpace.Preserve);
            xrData.Dispose();

#pragma warning disable 0618
            XmlValidatingReader xrTemp = new XmlValidatingReader(new XmlTextReader(Path.Combine(_strPath, _strXslFile)));
            xrTemp.ValidationType = ValidationType.None;
            xrTemp.EntityHandling = EntityHandling.ExpandEntities;
            xsltSameInstance.Load(xrTemp);
        }
예제 #4
0
파일: CXmlCache.cs 프로젝트: shmao/corefx
    public bool Load(string strFileName)
    {
#pragma warning disable 0618
        XmlTextReader rXmlTextReader;
        XmlValidatingReader rXmlValidatingReader;
        bool fRet;

        rXmlTextReader = new XmlTextReader(strFileName);
        rXmlTextReader.WhitespaceHandling = _eWhitespaceMode;
        rXmlTextReader.Namespaces = _fNamespaces;

        _eEncoding = rXmlTextReader.Encoding;

        rXmlValidatingReader = new XmlValidatingReader(rXmlTextReader);
        rXmlValidatingReader.ValidationType = _eValidationMode;
        rXmlValidatingReader.EntityHandling = _eEntityMode;
#pragma warning restore 0618

        if (_fValidationCallback)
            rXmlValidatingReader.ValidationEventHandler += new ValidationEventHandler(this.ValidationCallback);

        try
        {
            fRet = Load((XmlReader)rXmlValidatingReader);
        }
        catch (Exception e)
        {
            fRet = false;
            rXmlValidatingReader.Dispose();
            rXmlTextReader.Dispose();

            if (_strParseError == string.Empty)
                _strParseError = e.ToString();

            if (_fThrow)
                throw (e);
        }

        rXmlValidatingReader.Dispose();
        rXmlTextReader.Dispose();
        return fRet;
    }
예제 #5
0
        // --------------------------------------------------------------------------------------------------------------
        //  LoadXSL_Resolver
        //  -------------------------------------------------------------------------------------------------------------
        public int LoadXSL_Resolver(string _strXslFile, XmlResolver xr, InputType inputType, ReaderType readerType)
        {
            _strXslFile = FullFilePath(_strXslFile);
#pragma warning disable 0618
            xslt = new XslTransform();
#pragma warning restore 0618

            switch (inputType)
            {
            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);
        }