XML Precauciones


Aquí se enumeran las tecnologías que debe evitar usar cuando utilice XML.


Internet Explorer - Islas de datos XML

¿Qué es?Una isla de datos XML son datos XML incrustados en una página HTML.

¿Por qué debe evitarse?Las islas de datos XML solo funcionan en el navegador Internet Explorer.

¿Qué se puede usar en su lugar?Debe usar JavaScript y XML DOM en HTML para analizar y mostrar XML.

Para obtener más información sobre JavaScript y XML DOM, visite nuestroTutorial de XML DOM。


Ejemplo de isla de datos XML

Este ejemplo utiliza el documento XML ""。

Vincule el documento XML a una etiqueta `<xml>` en el documento HTML. El atributo `id` define el identificador de la isla de datos, mientras que el atributo `src` apunta al archivo XML:

Ejemplo

Este ejemplo solo es compatible con el navegador IE.

<html>
<body>

<xml id="cdcat" src="cd_catalog.xml.html"></xml>

<table border="1" datasrc="../index.html">
<tr>
<td><span datafld="ARTIST"></span></td>
<td><span datafld="TITLE"></span></td>
</tr>
</table>

</body>
</html>

Pruébalo »

El atributo `datasrc` de la etiqueta `<table>` vincula la tabla HTML a la isla de datos XML.

La etiqueta `<span>` permite que el atributo `datafld` haga referencia a los elementos XML que se mostrarán. En este ejemplo, se hace referencia a `"ARTIST"` y `"TITLE"`. Al leer el XML, se crea una fila de tabla para cada elemento `<CD>`.


Internet Explorer - Comportamientos

¿Qué es?Internet Explorer 5 introdujo los comportamientos. Un comportamiento es un método para agregar comportamiento a elementos XML (o HTML) mediante estilos CSS.

¿Por qué debe evitarse?Solo Internet Explorer admite el atributo `behavior`.

¿Qué usar en su lugar?Utilice JavaScript y XML DOM (o HTML DOM) en su lugar.

Ejemplo 1 - Resaltado al pasar el ratón

El elemento `<style>` en el siguiente archivo HTML define un comportamiento para el elemento `<h1>`:

<html>
<head>
<style type="text/css">
h1 { behavior: url(behave.htc) }
</style>
</head>
<body>

<h1>Mouse over me!!!</h1>

</body>
</html>

A continuación se muestra el documento XML `"behave.htc"` (el archivo contiene código JavaScript y controladores de eventos para el elemento):

<attach for="element" event="onmouseover" handler="hig_lite" />
<attach for="element" event="onmouseout" handler="low_lite" />

<script>
function hig_lite()
{
element.style.color='red';
}

function low_lite()
{
element.style.color='blue';
}
</script>

Pruébalo »

Ejemplo 2 - Simulador de máquina de escribir

El elemento `<style>` en el siguiente archivo HTML define un comportamiento para el elemento con `id="typing"`:

<html>
<head>
<style type="text/css">
#typing
{
behavior:url(typing.htc);
font-family:'courier new';
}
</style>
</head>
<body>

<span id="typing" speed="100">IE5 introduced DHTML behaviors.
Behaviors are a way to add DHTML functionality to HTML elements
with the ease of CSS.<br /><br />How do behaviors work?<br />
By using XML we can link behaviors to any element in a web page
and manipulate that element.</p>v </span>

</body>
</html>

A continuación se muestra el documento XML `"typing.htc"`:

<attach for="window" event="onload" handler="beginTyping" />
<method name="type" />

<script>
var i,text1,text2,textLength,t;

function beginTyping()
{
i=0;
text1=element.innerText;
textLength=text1.length;
element.innerText="";
text2="";
t=window.setInterval(element.id+".type()",speed);
}

function type()
{
text2=text2+text1.substring(i,i+1);
element.innerText=text2;
i=i+1;
if (i==textLength)
{
clearInterval(t);
}
}
</script>

Pruébalo »

Otras extensiones