home HOME

XML Basic
XML HOME
XML Introduction
XML How to use
XML Syntax
XML Elements
XML Attributes
XML Validation
XML Validator
XML Browsers
XML Viewing
XML CSS
XML XSL
XML Data Island
XML in Real Life
XML Parser

XML Advanced
XML Namespaces
XML CDATA
XML Encoding
XML Server
XML Application
XML HTTP Request
XML Save Data
XML Behaviors
XML Technologies
XML Editors
XML Summary

Examples/Quiz
XML Examples
XML Quiz

Selected Reading
Web Statistics
Web Glossary
Web Hosting
Web Quality

W3Schools Forum

Helping W3Schools

pixels

XML Data Island

prev next

With Internet Explorer, the unofficial <xml> tag can be used to create an XML data island.


XML Data Embedded in HTML

An XML data island is XML data embedded into an HTML page.

Here is how it works; assume we have the following XML document ("note.xml"):

<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
  <to>Tove</to>
  <from>Jani</from>
  <heading>Reminder</heading>
  <body>Don't forget me this weekend!</body>
</note>

Then, in an HTML document, you can embed the XML file above with the <xml> tag. The id attribute of the <xml> tag defines an ID for the data island, and the src attribute points to the XML file to embed:

<html>
<body>
<xml id="note" src="note.xml"></xml>
</body>
</html>

However, the embedded XML data is, up to this point, not visible for the user.

The next step is to format and display the data in the data island by binding it to HTML elements.


Bind Data Island to HTML Elements

In the next example, we will embed an XML file called "cd_catalog.xml" into an HTML file.

View "cd_catalog.xml".

The HTML file looks like this:

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

Example explained:

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

<td> tags cannot be bound to data, so we are using <span> tags. The <span> tag allows the datafld attribute to refer to the XML element to be displayed. In this case, it is datafld="ARTIST" for the <ARTIST> element and datafld="TITLE" for the <TITLE> element in the XML file. As the XML is read, additional rows are created for each <CD> element.

If you are running IE 5.0 or higher, you can try it yourself.

Also try this example, demonstrating <thead>, <tbody>, and <tfoot>.


prev next

Jump to: Top of Page or HOME or Printer Friendly Printer friendly page

W3Schools provides material for training only. We do not warrant the correctness of its contents. 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-2007 by Refsnes Data. All Rights Reserved.

Validate Validate W3C-WAI level A conformance icon W3Schools was converted to XHTML in December 1999