Browser support for XML external entities
Today I was working with writing an XML log file and finding a nice way to view it in a browser. I threw together some xsl to display my log entries and added the stylesheet reference at the top:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="log.xsl"?>
Modern browsers reading this XML file will actually get the xsl file, apply the transform and show you the result (HTML in this case).. nifty! But of course at this point I hit the fundamental problem with XML logs.. while the log is in use it is generally not well formed XML because the final closing tag is missing (neither java.util.logging nor log4j appear to do any tricks to write the closing tag and overwrite it again on each new entry). From the log4j documentation I got the idea to try using an XML external entity to make a well formed document in another file, while the log file itself can still be simply appended.
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="log.xsl"?>
<!DOCTYPE log [
<!ENTITY logdata SYSTEM "log.xml">
]>
<log>
&logdata;
</log>
Nice and simple.. I accessed this in my browser (Firefox) and found that no log entries were shown. It seems that Firefox recognizes the entity but does not expand it. I tried Opera and found that it didn't process the entity at all so &logdata; was visible. For kicks I then tried IE7.. to my surprise, it worked exactly as it should.. the external entity was processed and the XSL applied to get my nice log display.
Posted at 06:35PM Apr 27, 2007 by mindless in Sun | Comments[0]