Jump to content

Problem using XML Data Islands with Firefox/Opera


Recommended Posts

Hi, I'm trying to embed XML data islands into an html page. I followed the instructions presented in W3's tutorial but the darn browser has really something against me... The xml content isn't visible at all in FF and Opera, however I can see it on IE6. Below is the piece of code I'm using in both my html and xml file.Here's my HTML code:

<!DOCTYPE htmlPUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

			<div class="content">				<xml id="update" src="update.xml"></xml>								<table datasrc="#update" border="1">				<tr><td><span datafld="TITLE"></span></td></tr>				<tr><td><span datafld="BODY"></span></td></tr>				</table>			</div>

Here's my XML code:

<UPDATES><NEW><TITLE>Title</TITLE><BODY>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</BODY></NEW></UPDATES>

Viewing the html page on FF and Opera, I only get a 2 rows/1 column empty table, which should actually be: 1/1 = Title,2/1 = Content. I have googled for answers but to no avail. Can anyone please tell me what am I doing wrong? >.<Could it be I can't embed xml data directly into an html file? Thanks in advance, any help is highly appreciated. =)

Link to post
Share on other sites
Could it be I can't embed xml data directly into an html file?
Not with data islands, no. You can't.You can do it with JavaScript, or better yet - PHP or another S3L.In JavaScript, you can do it by replacing your HTML:
			<div class="content">				<xml id="update" src="update.xml"></xml>								<table datasrc="#update" border="1">				<tr><td><span datafld="TITLE"></span></td></tr>				<tr><td><span datafld="BODY"></span></td></tr>				</table>			</div>

with something like:

			<div class="content">								<table border="1">				<tr><td id="TITLE"></td></tr>				<tr><td id="BODY"></td></tr>				</table><script type="text/javascript" src="http://w3schools.com/dom/loadxmldoc.js"></script><script type="text/javascript">var xmlDoc=loadXMLDoc("books.xml");document.getElementById('TITLE').innerHTML = xmlDoc.getElementsByTagName('TITLE')[0].innerHTML;document.getElementById('BODY').innerHTML = xmlDoc.getElementsByTagName('BODY')[0].innerHTML;</script>			</div>

This is a VERY simplified example that should work everywhere. For anything more complex involving JavaScript, read the XML DOM tutorial.

Link to post
Share on other sites

I see, thanks for the quick reply. ^^But in the tutorial it says:

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:
<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.
This all makes it sound like it's perfectly possible, plus the thing works pretty well in IE6. =þI will try with Javascript as I am still relunctant to learn PHP or any other server-side language. Will get there some day...
Link to post
Share on other sites
I see, thanks for the quick reply. ^^But in the tutorial it says:This all makes it sound like it's perfectly possible. =þI will try with Javascript as I am still relunctant to learn PHP or any order server-side language. Will get there some day...
The tutorial also mentions "If you are running IE 5.0 or higher," you know :)
Link to post
Share on other sites

I have a rare recessive psychological impairment that inhibits my poor eyes from clearly seeing bold-faced text. ( ´ ω`)Oh, and will using Javascript produce the exact same result as using Data islands? Will new table rows be automatically created for each new element in my .xml file or do I have to manually work them out? =)

Link to post
Share on other sites
I have a rare recessive psychological impairment that inhibits my poor eyes from clearly seeing bold-faced text. ( ´ ω`)Oh, and will using Javascript produce the exact same result as using Data islands? Will new table rows be automatically created for each new element in my .xml file or do I have to manually work them out? =)
The way I've made it above, no, but it can be done. You can create a loop ("for" most likely) that will do the same for each of the items in the NodeList containing all proper TDs, whereas this one does it manually only for the first one (matched by it's ID).Again, read more about JavaScript and DOM.
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...