XML Don't

|  | Search W3Schools : |

HOME | HTML | CSS | XML | JAVASCRIPT | ASP | PHP | SQL | MORE... |  | References | Examples | Forum | About

ADVERTISEMENTS XML Certification Download XML editor Custom Programming |  |

Table of contents

XML Basic
XML HOME
XML Introduction
XML How to use
XML Tree
XML Syntax
XML Elements
XML Attributes
XML Validation
XML Validator
XML Viewing
XML CSS
XML XSLT
XML JavaScript
XML Parser
XML DOM
XML to HTML
XML HTTP Request
XML Application
XML Advanced
XML Namespaces
XML CDATA
XML Encoding
XML Server
XML DOM Advanced
XML Don't
XML Technologies
XML in Real Life
XML Editors
XML Summary
Examples/Quiz
XML Examples
XML Quiz
XML Exam

Selected Reading

Web Statistics
Web Glossary
Web Hosting
Web Quality
W3Schools Tutorials
W3Schools Forum
Helping W3Schools

# XML Don't

Here are some technologies you should try to avoid when using XML.

## Internet Explorer - XML Data Islands

What is it? An XML data island is XML data embedded into an HTML page.

Why avoid it? XML Data Islands only works with Internet Explorer browsers.

What to use instead? You should use JavaScript and XML DOM to parse and display XML in HTML.

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

## XML Data Island Example

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

Bind the XML document to an <xml> tag in the HTML document. The id attribute defines an id for the data island, and the src attribute points to the XML file:

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

The datasrc attribute of the <table> tag binds the HTML table to the XML data island.

The <span> tags allow the datafld attribute to refer to the XML element to be displayed. In this case, "ARTIST" and "TITLE". As the XML is read, additional rows are created for each <CD> element.

If you are using Internet Explorer, you can try it yourself.

## Internet Explorer - Behaviors

What is it? Internet Explorer 5 introduced behaviors. Behaviors are a way to add behaviors to XML (or HTML) elements with the use of CSS styles.

Why avoid it? The behavior attribute is only supported by Internet Explorer.

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

## Example 1 - Mouseover Highlight

The following HTML file has a <style> element that defines a behavior for the <h1> element:

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

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

The XML document "behave.htc" is shown below:

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

    <script type="text/javascript">
    function hig_lite()
    {
    element.style.color='red';
    }

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

The behavior file contains a JavaScript and event handlers for the elements.

Try it yourself (mouse over the text in the example).

## Example 2 - Typewriter Simulation

The following HTML file has a <style> element that defines a behavior for elements with an id of "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>
    </span>
    </body>
    </html>

The XML document "typing.htc" is shown below:

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

    <script type="text/javascript">
    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 yourself

## Make your web applications look like a million bucks

Most web applications today use boring methods to present data to their viewers using grids or simple HTML tables. FusionCharts induces "life" into the web applications by converting monotonous data into lively charts, gauges & maps.

FusionCharts works with all technologies like ASP, ASP.NET, PHP, ColdFusion, Ruby on Rails, JSP, HTML pages etc. and connects to any database to render animated & interactive charts. It takes less than 15 minutes and no expertise whatsoever to build your first chart and just a glance of it to captivate your audience. This fact is endorsed by our 12,000 customers and 150,000 users which include a majority of the Fortune 500 companies. And yeah, your applications could look like a million bucks by spending just $69.

So go ahead, download your copy of FusionCharts and start "wow-ing" your customers now!

WEB HOSTING
ASP.NET Shopping Cart
$15 Domain Name Registration Save $20 / year!
Buy UK Domain Names Register Domain Names
Cheap Domain Names Cheap Web Hosting
Best Web Hosting
PHP MySQL Hosting
Top 10 Web Hosting
UK Reseller Hosting
Web Hosting
FREE Web Hosting

WEB BUILDING
Website Templates Flash Templates Website Builder Internet Business Opportunity
Custom Programming
FREE Trial or Demo Web Content Manager Forms,Web Alerts,RSS
Download XML editor
FREE Flash Website
FREE Web Templates

EDUCATION
US Web Design Schools
HTML Certification
JavaScript Certification
XML Certification
PHP Certification
ASP Certification

HOME or Top of Page |  | Printer Friendly
W3Schools is for training only. We do not warrant the correctness of its content. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy. Copyright 1999-2009 by Refsnes Data. All Rights Reserved.