Tag Archives: Dtd

W3C validator issues with ampersand (&) in javascript location.href

When I tried to validate the code for http://www.hyips.es (one of my freelance projects) the validator kept complaining:

cannot generate system identifier for general entity langpair.

This error is caused by the validator parsing the code inside of a <script> tag. Below are the lines which were producing the error (related to a function which translates the page from spanish to english using google translator):

<script type="text/javascript"> 
function es2eng(){
  location.href = "http://translate.google.com/translate?u=" + this.location.href + "&langpair=es|en&h1=es&ie=UTF-8"; 
}
</script>
<a href="#" onclick="es2eng();"><img style="border: medium none; margin:1px;" src="/images/banderas/england-flag.gif" alt="translate to english" height="20" width="30" /></a>

After reading a lot of confussing comments (like Try to change ‘&’ to ‘&amp;’ or to ‘%26′), and just when I was about to define the function in an external js file (not a big fan of this, because the function was only one line long…), I came to this revealing post in webmasterworld.com.

The problem can be solved as easy as this: change

<script type="text/javascript">
your script is here
</script>

To:

<script type="text/javascript">
// <![CDATA[
your script is here
// ]]>
</script>

The change stops W3C’s validator from parsing the code inside the script tags, therefore the error disappears! :-)

Posicionamiento en google (I): validando tus DTD's

Antes de seguir leyendo:
- Si no sabes qué es un DTD, búscalo en wikipedia

De cara a tener un alto pagerank en google, un aspecto que debemos verificar periódicamente es la validez de nuestros DTD’s. Además, tener un código válido, limpio y organizado mejora notablemente el aspecto de nuestra página web, aportándole solidez.

Validando el DTD
Podemos utilizar múltiples herramientas para validar el código fuente de nuestras páginas. Yo suelo utilizar el Validador del W3C.

Éste validador lee el código fuente de nuestra página, consulta el DTD que estamos utilizando y valida nuestro código contra ese DTD. Si nuestro código es incorrecto nos muestra los errores que tiene y, normalmente, nos da pistas sobre cómo solventarlos.

Para mis páginas suelo utilizar el DTD Transitional.
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Por ejemplo, para validar la corrección del DTD, basta con pulsar en este enlace

Si la validación pasa sin errores, podremos incluir el siguiente logo en nuestro sitio.

Valid XHTML 1.0 Transitional