예제 #1
0
        public XPathNavigator GetDocument(Uri uri)
        {
            XPathNavigator result;

            if (docCache != null)
            {
                result = docCache [uri] as XPathNavigator;
                if (result != null)
                {
                    return(result.Clone());
                }
            }
            else
            {
                docCache = new Hashtable();
            }

            XmlReader rdr = null;

            try {
                rdr = new XmlTextReader(uri.ToString(), (Stream)resolver.GetEntity(uri, null, null), root.NameTable);
                XmlValidatingReader xvr = new XmlValidatingReader(rdr);
                xvr.ValidationType = ValidationType.None;
                result             = new XPathDocument(xvr, XmlSpace.Preserve).CreateNavigator();
            } finally {
                if (rdr != null)
                {
                    rdr.Close();
                }
            }
            docCache [uri] = result.Clone();
            return(result);
        }
예제 #2
0
        public static XPathNavigator LoadCacheFile(string file)
        {
            string key = "file:" + file;

            System.Web.Caching.Cache cache = HttpContext.Current.Cache;

            XPathNavigator nav = cache[key] as XPathNavigator;

            if (nav != null)
            {
                return(nav.Clone());
            }

            try {
                SandboxDownload(file);
                using (TextReader r = new StreamReader(file))
                    nav = new XPathDocument(new XmlTextReader(r)).CreateNavigator();
            } catch (ArgumentException e) {
                throw new ArgumentException("Error loading " + file, e);
            }
            cache.Insert(key, nav, new System.Web.Caching.CacheDependency(file));
            Console.Error.WriteLine("Caching: " + key);

            return(nav.Clone());
        }
		public XPathNavigator GetDocument(Uri uri)
		{
			XPathNavigator xpathNavigator;
			if (this.docCache != null)
			{
				xpathNavigator = (this.docCache[uri] as XPathNavigator);
				if (xpathNavigator != null)
				{
					return xpathNavigator.Clone();
				}
			}
			else
			{
				this.docCache = new Hashtable();
			}
			XmlReader xmlReader = null;
			try
			{
				xmlReader = new XmlTextReader(uri.ToString(), (Stream)this.resolver.GetEntity(uri, null, null), this.root.NameTable);
				xpathNavigator = new XPathDocument(new XmlValidatingReader(xmlReader)
				{
					ValidationType = ValidationType.None
				}, XmlSpace.Preserve).CreateNavigator();
			}
			finally
			{
				if (xmlReader != null)
				{
					xmlReader.Close();
				}
			}
			this.docCache[uri] = xpathNavigator.Clone();
			return xpathNavigator;
		}