[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
How_To_XML_Display_XML_In_HTML_Table_DataIslands

How to display XML elements in an HTML table using Data Islands?

To bind your XML data to an HTML table, add the datasrc (data source) attribute to the <table> element, then add the datafld (data field) attributes to any other inline eg. <div>, <span> or <input> tags between the <td> elements. (The <td> element itself cannot have the datasrc attribute.)

<xml id="books">
<?xml version="1.0"?>
<books>
   <book>
	<title>OpenGL Programming Guide Fourth Edition</title>
	<location>107</location>
	<publisher>Addison-Wesley</publisher>
	<year>2004</year>
   </book>
   <book>
	<title>Curves and Surfaces for CAGD: A Practical Guide</title>
	<location>116</location>
	<publisher>Academic Press</publisher>
	<year>2002</year>
   </book>
   <book>
	<title>An Introduction to NURBS: With Historical Perspective</title>
	<location>120</location>
	<publisher>Academic Press</publisher>
	<year>2001</year>
   </book>
   <book>
	<title>NURBS: From Projective Geometry to Practical Use</title>
	<location>126</location>
	<publisher>A K Peters</publisher>
	<year>1999</year>
   </book>
</books>
</xml>


The datasrc attribute element references the id attribute of the <xml> tag and binds the XML data to the HTML table.

<table width="100%" cellpadding="0" cellspacing="2" border="0" datasrc="#books"> 
 <thead>
   <tr>
	<th>Title</th>
	<th>Location</th>
	<th>Publisher</th>
	<th>Year</th>
   </tr>
 </thead>
 <tbody>
   <tr>
    	<td><span datafld="title"></span></td>
	<td><span datafld="location"></span></td>
    	<td><span datafld="publisher"></span></td>
	<td><span datafld="year"></span></td>
   </tr>
 </tbody>
</table>


XML FAQ

last edited (April 19, 2004) by lillu, Number of views: 1949, Current Rev: 5 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.