<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>XML and XmlDataSource Control</title><link>http://forums.asp.net/43.aspx</link><description>All about XML, XSLT, and the XmlDataSource control.</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Re: Caching XML file when using XmlTextReader</title><link>http://forums.asp.net/thread/3271329.aspx</link><pubDate>Thu, 02 Jul 2009 12:51:19 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3271329</guid><dc:creator>katebp</dc:creator><author>katebp</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3271329.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=43&amp;PostID=3271329</wfw:commentRss><description>&lt;p&gt;Ah, brilliant - thanks.&lt;/p&gt;
&lt;p&gt;I am now trying to work out how to cache the xslt files, so I don&amp;#39;t have to load each one...&lt;/p&gt;
&lt;p&gt;K&lt;/p&gt;</description></item><item><title>Re: Caching XML file when using XmlTextReader</title><link>http://forums.asp.net/thread/3269413.aspx</link><pubDate>Wed, 01 Jul 2009 16:40:04 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3269413</guid><dc:creator>Martin_Honnen</dc:creator><author>Martin_Honnen</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3269413.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=43&amp;PostID=3269413</wfw:commentRss><description>&lt;p&gt;&amp;nbsp;I don&amp;#39;t think caching an Xml(Text)Reader makes any sense as it is basically an API to parse through an XML document once in a forwards only manner. So what would you want to do with the XmlTextReader when you retrieve it from the cache? Reset it? That is not possible.&lt;/p&gt;
&lt;p&gt;You can try to cache the XPathDocument however, that is an in-memory data structure you should be able to reuse.&lt;/p&gt;</description></item><item><title>Caching XML file when using XmlTextReader</title><link>http://forums.asp.net/thread/3269229.aspx</link><pubDate>Wed, 01 Jul 2009 15:07:29 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3269229</guid><dc:creator>katebp</dc:creator><author>katebp</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3269229.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=43&amp;PostID=3269229</wfw:commentRss><description>&lt;p&gt;&amp;nbsp;Hello all,&lt;/p&gt;
&lt;p&gt;I am currently working on a site when the navigation elements (top nav, left menu, breadcrumbs etc) are contained within user controls which individually load in the sitemap xml and use XslCompiledTransform to parse it through dfferent XSLT files.&lt;/p&gt;
&lt;p&gt;I am currently working on how I can cache the sitemap xml so it isn&amp;#39;t loaded from scratch four or five times&amp;nbsp;every time the page is loaded.&lt;/p&gt;
&lt;p&gt;from sitetemplate.master.cs&amp;nbsp;&lt;/p&gt;&lt;pre class="c-sharp" name="code"&gt;using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Caching;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Xsl;
using System.Xml.XPath;


public partial class sitetemplate : System.Web.UI.MasterPage
{

    protected void Page_Load(object sender, EventArgs e)
    {
        //validate all values in querystring
        foreach (string i in Request.QueryString.AllKeys)
        {
            string ivalue = Request.QueryString[i];
            if (!Regex.IsMatch(ivalue, &amp;quot;^[0-9a-zA-Z]&amp;quot;))
            {
                // invalid char. Redirect to pageid
                Response.Redirect(&amp;quot;error.aspx?error=invalchar&amp;quot;);
            }
        }

        // site xml
        XmlTextReader siteXML;

        // loading xml from cache 
        siteXML = (XmlTextReader)HttpContext.Current.Cache.Get(&amp;quot;dotnettemplate&amp;quot;);
        Response.Write(&amp;quot;// loading xml from cache &amp;quot;);
        if (siteXML == null)
        {
            // not found in cache, retrieve from file 
            siteXML = new XmlTextReader(Server.MapPath(&amp;quot;~/xml/dotnettemplate.sitemap&amp;quot;));
            Response.Write(&amp;quot;// not found in cache, retrieve from file&amp;quot;);
            // save to cache 
            Cache.Insert(&amp;quot;dotnettemplate&amp;quot;, siteXML, new CacheDependency(Server.MapPath(&amp;quot;~/xml/dotnettemplate.sitemap&amp;quot;)), Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, null);
        }
        //Cache.Remove(&amp;quot;dotnettemplate&amp;quot;);
        XPathDocument xpathDoc = new XPathDocument(siteXML);

        //Section menu
        XmlTextReader sectionXSL = new XmlTextReader(Server.MapPath(&amp;quot;~/xslt/SectionMenu.xslt&amp;quot;));
        XslCompiledTransform SectionNavMenu = new XslCompiledTransform();

        // Create the XsltArgumentList
        XsltArgumentList xslArg = new XsltArgumentList();

        SectionNavMenu.Load(sectionXSL);

        StringBuilder sb = new StringBuilder();
        using (StringWriter sw = new StringWriter(sb))
        {
            SectionNavMenu.Transform(xpathDoc, xslArg, sw);
            litSectionMenu.Text = sw.ToString();
        }
        sectionXSL.Close();
        siteXML.Close();
        xslArg.Clear();
        sb = null;
        
       }
}&lt;/pre&gt;
&lt;p&gt;The code appears to save the xml to the cache, but doesn&amp;#39;t retrieve it properly.&lt;/p&gt;
&lt;p&gt;If I substitute all the cache stuff above for:&lt;/p&gt;
&lt;p&gt;XmlTextReader siteXML = new XmlTextReader(Server.MapPath(&amp;quot;~/xml/dotnettemplate.sitemap&amp;quot;));&lt;/p&gt;
&lt;p&gt;it works fine.&lt;/p&gt;
&lt;p&gt;This&amp;nbsp;post&amp;nbsp;covered a similar problem: &lt;a href="http://forums.asp.net/p/1300194/2539950.aspx#2539950"&gt;http://forums.asp.net/p/1300194/2539950.aspx#2539950&lt;/a&gt;&amp;nbsp;but&amp;nbsp;I thought that XmlDocument shouldn&amp;#39;t be used (and I couldn&amp;#39;t get it to work with XmlTextReader any way).&lt;/p&gt;
&lt;p&gt;Any ideas?&lt;br /&gt;&amp;nbsp;&lt;/p&gt;</description></item></channel></rss>