Click to See Complete Forum and Search --> : [RESOLVED] Data binding


ajajajak
01-14-2010, 08:22 AM
Hey

XML:

<?xml version="1.0" encoding="utf-8"?>
<photobook_cat>
<BOOK>
<title>LASZLO MOHOLY-NAGY</title>
<publisher>Phaidon</publisher>
<year>2001</year>
</BOOK>
<BOOK>
<title>EADWEARD MUYBRIDGE</title>
<publisher>Phaidon</publisher>
<year>2001</year>
</BOOK>
<BOOK>
<title>THE AMERICANS - Robert Frank</title>
<publisher>Steidl</publisher>
<year>2008</year>
</BOOK>
<BOOK>
<title>DOG DAYS BOGOTA - Alec Soth</title>
<publisher>Steidl</publisher>
<year>2007</year>
</BOOK>
</photobook_cat>


HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Databinding via xml & data-isles</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>

<xml id="photobook_cat" src="photobook_cat.xml"></xml>

<table border="1" datasrc="#photobook_cat">

<thead>
<tr>
<th>Title</th>
<th>Publisher</th>
<th>Year</th>
</tr>
</thead>

<tfoot>
<tr>
<th colspan="3">This is a concised outtake of my photobook collection</th>
</tr>
</tfoot>

<tbody>
<tr>
<td><span datafld="title"></span></td>
<td><span datafld="publisher"></span></td>
<td><span datafld="year"></span></td>
</tr>
</tbody>
</table>
</body>
</html>


I do not succeed in retrieving data from the xml file. Any idea why it doesn't work?

Also I tried using several doctypes(strict/tranistional/frameset) and they all failed at validation. Is there a way to have a valide document when you want to include xml data into the html document?

ajajajak
01-15-2010, 05:29 AM
No one? ;)

Charles
01-15-2010, 06:36 PM
I'm not sure why you think that it would work. What exactly are you trying to accomplish?

ajajajak
01-17-2010, 11:52 AM
What I am trying to do is import data from the xml file into the html document and more specifically into a 3 column table.

First I import the xml file I want to extract data from (xml-isle)

<xml id="photobook_cat" src="photobook_cat.xml"></xml>


link the table structure to the xml file with the datasrc attribute(data-binding)

<table border="1" datasrc="#photobook_cat">


and import the data via the datafld attribute(data-binding)

<td><span datafld="title"></span></td>
<td><span datafld="publisher"></span></td>
<td><span datafld="year"></span></td>


I am aware that this process needs a flawless table structure and runs in IE5+ browsers only but even when taking these requirements into account it still doesn't work.

Powersurge360
01-17-2010, 01:58 PM
The best way to do this would be using a transformation language, namely XSLT. More brutish ways could be with a server side scripting language or Javascripts XMLHTTPRequest object, but they all have their caveats.

If I could give only one answer, I'd say use XSLT. It's relatively simple to pick up if you already know the language you are converting to.

Charles
01-17-2010, 02:35 PM
XSLT is the way to go. Check the "Accept" request header and if the browser accepts XML then send the page as a mix of XHTML and XML but with an XSLT stylesheet linked. If the browser doesn't support XML then do the transformation server side.

ajajajak
01-19-2010, 10:31 AM
I will look into that.
Thank you for your help.