views:

35

answers:

2

i have a web-page that returns XML with an xsl stylesheet transform, e.g.:

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type='text/xsl' href='/css/homepage.xsl'?>
<MyData>
   ...
</MyData>

It properly displays the transformed XSL as HTML. But when i try to view the XML source, Internet Explorer gives me the error:

The XML source file is unavailable for viewing

Some people claim that this behaviour is by design.

But i can give you a site where the desired behaviour works perfectly (Blizzards WoW Armory) (i.e. you can view the xml source):

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="/_layout/pageIndex.xsl"?>
<page globalSearch="1" lang="es_mx" requestUrl="/index.xml" type="front">
  <pageIndex>
    <related-info/>
  </pageIndex>
</page>

So the argument that "this behaviour is by design" is disproven by direct observation.

What is wrong with my XML, that the source XML cannot be shown?


Leading you down the wrong path

Here is some supplemental information.

Http response headers from Blizzard's (working) site:

GET http://www.wowarmory.com/ HTTP/1.1

HTTP/1.1 200 OK
...
Content-Type: text/xml;charset=UTF-8
Content-Length: 233

<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="/_layout/pageIndex.xsl"?><page globalSearch="1" lang="es_mx" requestUrl="/index.xml" type="front">
  <pageIndex>
    <related-info/>
  </pageIndex>
</page>

And here are the response headers from my (borken) xml:

GET http://www.example.com/default.ashx HTTP/1.1

HTTP/1.1 200 OK
...
Content-Type: text/xml; charset=utf-8
...
Content-Length: 131974

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type='text/xsl' href='/css/homepage.xsl'?>
<MyData>
   ...
</MyData>

See also

+1  A: 

I can't reproduce this behavior. Check my XML/XSLT driven site http://www.aranedabienesraices.com.ar

With IE8, I can see the source and transformation result (Tools menu).

Could it be related to private cache?

Alejandro
Your page is `xhtml`, with a stylesheet; as opposed to arbitrary `xml` (i.e. it's still html, and the browser can treat look at it as such)
Ian Boyd
@Ian Boyd: Did you check the headers? IE doesn't handle 'xhtml'. What a send trough wire is `xml`. It is the transformation wich result in `xhtml`. If I was sending `html`, it would be no transformation.
Alejandro
A: 

tl;dr: no-cache was turned on

Long Version

i stumbled across a blog post from a guy having a similar problem:

Using the automatic debugging feature of Fiddler (a feature i'd never used), he narrowed it down the presence of a particular entry in the response headers:

Vary: *

He didn't understand why this header is causing IE to break, but he was able to remove it, and it fixed his problem. i don't have the vary: 0 header in my response, but it did give me a direction.

i was reading the documentation that deals with this option: HttpCachePolicy.SetOmitVaryStar Method. One thing caught my eye:

Note The use of the vary:* header can disable all client caching.

And so i wondered if the reason that "the XML source isn't available for viewing" is that there's a policy in place forcing IE to delete the XML source as soon as it's done (i.e. don't cache it)

Following in this guy's footsteps, i dug out fiddler and turned on the Automatic breakpoints after response feature. Turns out you can then muck with the response headers, rearranging, adding, changing, deleting stuff.

Original headers (fails)

HTTP/1.1 200 OK
Date: Thu, 01 Jul 2010 02:53:35 GMT
Server: Microsoft-IIS/7.0
Cache-Control: no-cache
Pragma: no-cache
Content-Type: text/xml; charset=utf-8
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Content-Length: 134772
Via: 1.1 www.example.com

<?xml version="1.0" encoding="utf-8"?>
...

i noticed that my headers have entries relating to caching:

Cache-Control: no-cache
Pragma: no-cache

perhaps if i remove those? i go into the spot in fiddler and manually delete those two lines, leaving:

Remove cache control headers

HTTP/1.1 200 OK
Date: Thu, 01 Jul 2010 02:55:06 GMT
Server: Microsoft-IIS/7.0
Content-Type: text/xml; charset=utf-8
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Content-Length: 134772
Via: 1.1 www.example.com

<?xml version="1.0" encoding="utf-8"?>
...

Note: The headers are not there by mistake, the content is always stale, and i want the client to refresh every time.

My initial solution fixes the problem, but introduces a new one - since the content is always stale. While i want ie to fetch every time, i don't really want it to delete its own local copy.

The line in the ashx that's giving me grief is:

//client don't cache it (it's too volatile)
context.Response.Cache.SetCacheability(HttpCacheability.NoCache); 

which turns into:

Cache-Control: no-cache

Removing the line leaves Cacheability as its default (Private), giving the response value:

Cache-Control: private

This allows the client to cache the content, and i can view source in the browser.

Ian Boyd
@Ian Boyd: So, it is realeated to cache headers like I said.
Alejandro
@Alejandro Yes, it seems to be; in the way that the private cache doesn't exist
Ian Boyd