Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

XML considerations


May 27, 2021 XML


Table of contents


XML considerations

In order to be sure that you are using XML correctly, you need to be aware of which actions are allowed and which are not supported by XML. Read this section carefully to learn more!

Here are the techniques you should try to avoid when using XML.


Internet Explorer - XML Data Island

What is it? XML data islands are XML data embedded in HTML pages.

Why avoid using it? XML Data Island is only valid in Internet Explorer browsers.

What to replace it with? You should use JavaScript and XML DOM in HTML to parse and display XML.

For more information about JavaScript and XML DOM, visit our XML DOM tutorial.


XML data island instance

This example uses the XML document "cd_catalog.xml."

Bind the XML document to a label in the HTML document. The id property defines the identifier of the data island, while the src property points to the XML file:

This example applies only to IE browsers

<html>
<body>

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

<table border="1" datasrc="#cdcat">
<tr>
<td><span datafld="ARTIST"></span></td>
<td><span datafld="TITLE"></span></td>
</tr>
</table>

</body>
</html>

Try it out . . .

The datasrc property of the label binds the HTML table to the XML data island.

The label allows the datafld property to reference the XML element to be displayed. I n this example, "ARTIST" and "TITLE" are to be referenced. When you read XML, the appropriate table rows are created for each of the elements.


Internet Explorer - Behavior

What is it? /b10>Internet Explorer 5 introduces behavior. Behavior is a way to add behavior to an XML (or HTML) element by using a CSS style.

Why avoid using it? Only Internet Explorer supports the behavior property.

What to use instead of it? Use JavaScript and XML DOM (or HTML DOM) instead of it.

Instance 1 - The mouse hover is prominent

The following HTML file defines a behavior for the element:

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

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

</body>
</html>

Shown below is the XML document "behave.htc" (which contains a JavaScript and an event handle for elements):

<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>

Try it out . . .

Example 2 - Typewriter simulation

The following HTML file defines a behavior for an element with id as "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>

The following is the XML document "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>

Try it out . . .

Tip: If you need it, you can read the section "HTML slt;style sgt; tags" on this site.