views:

26

answers:

2

For our application, we log in notepad. We provided web URL to user to view log. We save file on file system. Our users are not able to open some of the log file. Can anyone help me here? we store text/xml inside the .txt file. we are getting following error while trying to see a log file

The XML page cannot be displayed 
Cannot view XML input using style sheet. Please correct the error and then click 
the Refresh button, or try again later. 

--------------------------------------------------------------------------------

Invalid at the top level of the document. Error processing resource 

If someone can help me, i can send .txt files to them. This text file open successfully in Chrome and firefox

"SAVE THIS AS .txt AND TRY TO OPEN WITH IE"

2010-10-14 08:38:49,452 [1] DEBUG -

UserHostAddress 198.96.178.33 UserHostName 198.96.178.33 UserAgent Jakarta Commons-HttpClient/3.0.1 10/14/2010 8:38:49 AM Request factivafacpassword1230IBM1100Name10/14/2010 08:38:45

2010-10-14 08:38:51,983 [1] DEBUG -

Response 10/14/2010 8:38:51 AM 13201116695SANIBM Canada Credit Services Company,CanadaManitoba Securities Commission Enforcement Orders & Exceptions3201158540SANInternational Business Machines Corporation,United StatesSEC - Litigation Releases210/14/2010 8:38:51 AM 2010-10-14 08:39:30,452 [7] DEBUG -

UserHostAddress 198.96.178.33 UserHostName 198.96.178.33 UserAgent Jakarta Commons-HttpClient/3.0.1 10/14/2010 8:39:30 AM Request factivafacpassword1230CFX Holdings1100Name10/14/2010 08:39:30

2010-10-14 08:39:30,967 [7] DEBUG -

Response 10/14/2010 8:39:30 AM 1010/14/2010 8:39:30 AM

+2  A: 

IE is interpreting the file as an xml document and trying to open it. But the file does not seem to be in correct xml format. hence you are getting the error.

Sachin Shanbhag
jatin
A: 

It sounds like you are being bitten by type sniffing.

When IE receives a resource of type text/plain (as will normally be served for .txt), it doesn't trust that type.

(This is because web servers default to passing the type text/plain when they don't know what type a resource is, instead of simply omitting the Content-Type header. This is the Wrong Thing, but most web servers do it.)

Instead, IE looks at the beginning of the file to see if there's anything in there it recognises. If it sees something like <?xml that looks like XML, it'll decide that the entire file is text/xml, and not text/plain like the server said it was. This is of course also the Wrong Thing, and has caused some serious security problems in the past, but MS can't disable it in IE now without breaking a load of existing poorly-administered sites.

Exactly when, how, and what types IE sniffs for is a complicated story. In IE8+, you can avoid this unpleasantness by returning your text/plain resources with the extra header:

X-Content-Type-Options: nosniff

As detailed on the IEBlog.

For earlier versions of IE it is difficult to stop random arbitrary text in a text/plain resource throwing off the sniffer. A simple but ugly solution if you need to support these IE versions is to fill the first 256 bytes of the file with content-free-filler (eg. 256 spaces). The sniffer only looks at this part of the file.

bobince
Does it mean that when i try to put XML in by log file, i should have 256 space before it?
jatin
If you need to support IE<8 and you don't fancy manually filtering out content that looks like other file types then yes, this is what you'd have to do. Messy, I know. Sorry.
bobince
@bobince It's not your fault. :)
bzlm