Monday, February 11, 2008

Setting the character encoding

Setting the character encoding is very important to import style sheets or Java scripts in an XML file. Normally this is not forgotten in a HTML or a JSP file.
Character encoding is set to unicode in the following line.
<meta equiv="Content-Type" content="text/html; CHARSET=UTF-8">

Once you have the above line in your xml/html file, you can link to style sheets successfully.
<link title="theme" rel="stylesheet" href="styles/tabstyle.css" type="text/css"/>

The XML file looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<html>
<head>
<title> Test </title>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8"/>
<link title="theme" rel="stylesheet" href="styles/tabstyle.css" type="text/css"/>

You can learn more about unicode in the following link.
http://www.w3.org/International/O-charset

Thursday, February 7, 2008

How to put a nbsp in xml without getting error

When you put a & nbsp ; in your xml file and then display it via an XSLT, you will get the following error:
"Fatal Error: The entity nbsp is referenced but not declared"

A work-around for this is to substitute "& nbsp ; " with "& #160 ; " in the xml file.
The error will not occur.


Resource

Setting class attribute to change style of an element

You can change the class (style) of an attribute in JavaScript.
An easy way to do this is:

element.setAttribute("class","styleClassName");
This works in firefox but not in IE

Another way to do it is:
element.setAttrbute("className", "styleClassName");
This works in IE but not in firefox.

An easy work-around that I found on web and which works on both IE and Firefox is:
element.setAttribute((document.all ? 'className' : 'class'), "styleClassName");

Resources:
http://www.quirksmode.org/bugreports/archives/2005/03/setAttribute_does_not_work_in_IE_when_used_with_th.html
http://www.digitalmediaminute.com/article/1394/the-browser-dom-and-the-class-attribute