none
IE Problems With Dynamic XML

    Question

  • Good evening,

    I am having some terrible problems with my Silverlight application in Internet Explorer.

    I have a php web form, which generates some figures - I've then get a small script that writes these files away to an XML file. My Silverlight application then reads the XML and generates a graph based on it (SL Toolkit). This all works perfectly in Chrome and Mozilla... However, in Internet Explorer, the data seems to get 'stuck', and I have to manually navigate to the XML URL, refresh it, go back to my graph and then refresh that before it will display the correct figures. I believe it may be something to do with Internet Explorer caching the XML file but I am not sure.

    I have tried almost everything and have spent ALOT of time looking around the internet.

    On the page that the Silverlight is on I have tried:
    "Pragma" CONTENT="no-cache"
    "Expires" CONTENT="-1"
    "Cache-Control" content="no-cache"

    I have tired deleting the XML file and then recreating it each time.
    and I have tried adding a random variable to the XML file call in C# - but I'm not entirely sure how this works.
    Here's what I'm using to get the XML file in my Page.Xaml.cs:
    WebClient xmlClient = new WebClient();
    xmlClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(XMLFileLoaded);
    xmlClient.DownloadStringAsync(new Uri("xml_tax.xml", UriKind.RelativeOrAbsolute));

    As I say, everything it working correctly in other browsers - but something is going wrong in IE.

    I would really appreciate some help/suggestions - I've become quite stuck.

    Thank you for your time,

    - W.
    Tuesday, March 03, 2009 7:27 PM

Answers

  • UPDATE:

    I think I have got to the bottom of it! I need to do some more testing but I thought I would share what I have found.

    I spent some time reading up on XMLHttpRequest and known problems related the the caching of data - this resource was especially useful: http://en.wikipedia.org/wiki/XMLHttpRequest

    To quote that article:
    Most of the implementations also realize HTTP caching. Internet Explorer and Firefox do, but there is a difference in how and when the cached data is revalidated. Firefox revalidates the cached response every time the page is refreshed, issuing an "If-Modified-Since" header with value set to the value of the "Last-Modified" header of the cached response.
    Internet Explorer does so only if the cached response is expired (i.e., after the date of received "Expires" header). This raises some issues, since a bug exists in Internet Explorer, where the cached response is never refreshed.

    (I believe the original source is from a Linksys site - http://www.ilinsky.com/articles/XMLHttpRequest/#bugs-ie-cache).

    So, to prevent XML from caching the behaviour needs to be unified on the client. That can be achieved through using the following BLOCKED SCRIPT

    var request = new XMLHttpRequest();
    request.open("GET", url, false);
    request.send(null);
    if(!request.getResponseHeader("Date")) {
    var cached = request;
    request = new XMLHttpRequest();
    var ifModifiedSince = cached.getResponseHeader("Last-Modified");
    ifModifiedSince = (ifModifiedSince) ?
    ifModifiedSince : new Date(0); // January 1, 1970
    request.open("GET", url, false);
    request.setRequestHeader("If-Modified-Since", ifModifiedSince);
    request.send("");
    if(request.status == 304) {
    request = cached;
    }
    }


    I am still curious as to why this worked locally before but not when live - do local sites not cache? Or is that a setting of the web server?

    I will let you know if this does turn out to be the solution - but so far so good.

    Thanks,

    - W.
    Wednesday, March 04, 2009 7:03 PM

All replies

  •  Hi,
    Kindly , sighlty clear with your Question..
    unable get Your problem

    Wednesday, March 04, 2009 5:56 AM
  • Apologies.

    I have a Silverlight graph, which builds based on the data which is held in an XML file. The XML file is dynamically updated.

    My problem is that, in Internet Explorer only, my graph does not display new information following changes to my XML file. I suspect the XML is being cached somewhere by IE.

    I would like to know of a way to fix this if possible or any suggestions.

    Thanks.
    Wednesday, March 04, 2009 10:04 AM
  •  Hi,

    It may Be silly ..R U Updating .xap(Silver Light).. file ..

    or U may Check Your Javascript by putting alert there may be some elment such as " Canvas " Which is Supported in Non IE Browser but not in IE Browser.

     

    Hope It help...

    Wednesday, March 04, 2009 10:18 AM
  • Hi,

    No I'm not updating the .xap file. I thought that by using the following I wouldn't have to?:

    WebClient xmlClient = new WebClient();
    xmlClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(XMLFileLoaded);
    xmlClient.DownloadStringAsync(new Uri("xml_tax.xml", UriKind.RelativeOrAbsolute));


    Can you please explain how I would do it?

    Many thanks.
    Wednesday, March 04, 2009 10:24 AM
  •  Hi,

    /*XmlClient.DownloadStringAsync(new Uri("xml_tax.xml", UriKind.RelativeOrAbsolute));*/

    Y donot U Try to Put..

    XmlClient.DownloadStringAsync(new Uri("http://<your server>/xml_tax.xml", UriKind.RelativeOrAbsolute));

    Hope It help

    Wednesday, March 04, 2009 10:30 AM
  • Thank you for that suggestion. However, it does not work either.

    It may be worth noting that it works correctly (even in IE) when hosted LOCALLY... But when uploaded to my webserver it does not work in IE.

    Working as expected in FireFox and Chrome.

    Thanks.
    Wednesday, March 04, 2009 10:40 AM
  • Good evening,

    I am still having problems with this - I thought I would more fully explain my problem.

    - I have created a pie chart using the Silverlight toolkit.
    - The data for the pie chart segments is retrieved from an XML file.
    - The data is retrieved and bound to my pie chart using the following code:

    namespace SilverlightApplication1
    {
    public partial class Page : UserControl
    {
    public Page()
    {
    InitializeComponent();
    InitializeGrid();
    }
    void InitializeGrid()
    {
    WebClient xmlClient = new WebClient();
    xmlClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(XMLFileLoaded);
    xmlClient.DownloadStringAsync(new Uri("xml_tax.xml", UriKind.RelativeOrAbsolute));
    }
    void XMLFileLoaded(object sender, DownloadStringCompletedEventArgs e)
    {
    if (e.Error == null)
    {
    string xmlData = e.Result;
    XDocument xdoc = XDocument.Parse(xmlData);
    var myData = from items in xdoc.Descendants("item")
    select new TaxBreakdown
    {
    Name = items.Element("label").Value,
    Value = items.Element("value").Value
    };
    PieSeries ps = BudgetAsPieChart.Series[0] as PieSeries;
    ps.ItemsSource = myData;
    }
    }
    }
    public class TaxBreakdown
    {
    public string Name { get; set; }
    public string Value { get; set; }
    }
    }


    - The XML file is stored in the /graphs/ClientBin, along with the .xap file.
    - The Silverlight.js is stored in /graphs.
    - They are all of relevant files I have (xml, xap, js).
    - I have a php form, which when submitted re-writes the XML file, and then the my Silverlight chart is supposed to display this information.
    - This works in Chrome and Firefox when live (on my webserver).
    - It might be important to know that it also works in Internet Explorer when offline (hosted locally).
    - The problem I am having, that when live, in internet explorer, the silverlight chart does not seem to read to XML after it has been updated.
    - If I manually navigate to the xml file in the address bar, and hit f5 to force it to refresh, and then go back to my graph and f5 that, the graph does eventually redraw - the thing is it is supposed to happen seamlessly.


    I don't understand why it is working in Chrome and Firefox and not in Internet Explorer (and I'm even more confused as to why it works in internet explorer when hosted locally).

    Your help really is appreciated! Please :)

    Thanks alot,

    - W
    Wednesday, March 04, 2009 4:25 PM
  • UPDATE:

    I think I have got to the bottom of it! I need to do some more testing but I thought I would share what I have found.

    I spent some time reading up on XMLHttpRequest and known problems related the the caching of data - this resource was especially useful: http://en.wikipedia.org/wiki/XMLHttpRequest

    To quote that article:
    Most of the implementations also realize HTTP caching. Internet Explorer and Firefox do, but there is a difference in how and when the cached data is revalidated. Firefox revalidates the cached response every time the page is refreshed, issuing an "If-Modified-Since" header with value set to the value of the "Last-Modified" header of the cached response.
    Internet Explorer does so only if the cached response is expired (i.e., after the date of received "Expires" header). This raises some issues, since a bug exists in Internet Explorer, where the cached response is never refreshed.

    (I believe the original source is from a Linksys site - http://www.ilinsky.com/articles/XMLHttpRequest/#bugs-ie-cache).

    So, to prevent XML from caching the behaviour needs to be unified on the client. That can be achieved through using the following BLOCKED SCRIPT

    var request = new XMLHttpRequest();
    request.open("GET", url, false);
    request.send(null);
    if(!request.getResponseHeader("Date")) {
    var cached = request;
    request = new XMLHttpRequest();
    var ifModifiedSince = cached.getResponseHeader("Last-Modified");
    ifModifiedSince = (ifModifiedSince) ?
    ifModifiedSince : new Date(0); // January 1, 1970
    request.open("GET", url, false);
    request.setRequestHeader("If-Modified-Since", ifModifiedSince);
    request.send("");
    if(request.status == 304) {
    request = cached;
    }
    }


    I am still curious as to why this worked locally before but not when live - do local sites not cache? Or is that a setting of the web server?

    I will let you know if this does turn out to be the solution - but so far so good.

    Thanks,

    - W.
    Wednesday, March 04, 2009 7:03 PM
  •  

    Hi Whilom

     

    my simple solution is here

     

    Random random = new Random();

    string sayi = random.Next(300, 300000000).ToString();

    _webClient.OpenReadAsync(new Uri("pageContent.xml?ID="+sayi, UriKind.Relative));

     

    :)

    Nice works man !

    Sunday, January 17, 2010 10:50 AM