www.webdeveloper.com
Results 1 to 7 of 7

Thread: [RESOLVED] Data binding

  1. #1
    Join Date
    Nov 2009
    Posts
    65

    resolved [RESOLVED] Data binding

    Hey

    XML:
    Code:
    <?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:
    HTML Code:
    <!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?
    Last edited by ajajajak; 01-14-2010 at 08:30 AM.

  2. #2
    Join Date
    Nov 2009
    Posts
    65
    No one?

  3. #3
    Join Date
    Nov 2002
    Location
    Baltimore, Maryland
    Posts
    12,279
    I'm not sure why you think that it would work. What exactly are you trying to accomplish?
    “The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
    —Tim Berners-Lee, W3C Director and inventor of the World Wide Web

  4. #4
    Join Date
    Nov 2009
    Posts
    65
    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)
    HTML Code:
    <xml id="photobook_cat" src="photobook_cat.xml"></xml>
    link the table structure to the xml file with the datasrc attribute(data-binding)
    HTML Code:
    <table border="1" datasrc="#photobook_cat">
    and import the data via the datafld attribute(data-binding)
    HTML Code:
    <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.

  5. #5
    Join Date
    Jan 2010
    Posts
    25
    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.

  6. #6
    Join Date
    Nov 2002
    Location
    Baltimore, Maryland
    Posts
    12,279
    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.
    “The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
    —Tim Berners-Lee, W3C Director and inventor of the World Wide Web

  7. #7
    Join Date
    Nov 2009
    Posts
    65
    I will look into that.
    Thank you for your help.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles