...

data-binding:: scrolling though XML records howto ?

firepages
12-21-2002, 03:20 AM
Hi, using the stuff below I can view all the current contacts that are stored in the contacts.xml.

How would I go about showing 1 record at a time ? with next/previous button ? - I could do this with forms and javascript but I would love to try it via XML if possible, it has to be basic stuff though i.e. it has to work in IE !

note this does not work in Moz but I am just as happy with a x-browser solution if it will degrade to IE5 as this does.

any pointers very much appreciated.


contacts.xml.....

<?xml version="1.0" encoding="ISO-8859-1"?>
<CONTACTS>
<CLIENT>
<NAME>Joe</NAME>
<SURNAME>Blogs</SURNAME>
<COMPANY>JB inc</COMPANY>
<HTTP>http://jb.inc</HTTP>
<EMAIL>jb@jb.inc</EMAIL>
</CLIENT>
<CLIENT>
<NAME>Joanna</NAME>
<SURNAME>Bloggs</SURNAME>
<COMPANY>JBB.inc</COMPANY>
<HTTP>http://jbb.inc</HTTP>
<EMAIL>jbb@jbb.inc</EMAIL>
</CLIENT>
</CONTACTS>



<html>
<body>
<xml id="contacts" src="contacts.xml"></xml>
<table border="1" cellpadding="10" cellspacing="0" datasrc="#contacts">
<thead>
<tr>
<th>Name</th>
<th>Surname</th>
<th>Company</th>
<th>Site</th>
<th>Email</th>
</tr>
</thead>
<tfoot>
<tr>
<th colspan="5">Contacts</th>
</tr>
</tfoot>
<tbody>
<tr>
<td><span datafld="name"></span></td>
<td><span datafld="surname"></span></td>
<td><span datafld="company"></span></td>
<td><a href=<span datafld="http"></span><span datafld="http"></span></a></td>
<td><a href=mailto:<span datafld="email"></span><span datafld="email"></span></a></td>
</tr>
</tbody>
</table>
</body>
</html>

firepages
12-21-2002, 03:48 AM
hmmm OK I googled this and got to w3schools who had this example which answers my question above, very cool BTW though IE only ( http://www.w3schools.com/xml/xml_applications.asp )

next Q though ;) is can I dynamically load another XML document at runtime, so say I load in an XML file with 50 contacts , can I load in another 50 at runtime without having to refresh the page ? - that would be very cool.

Also how would I go about doing the below in Moz?? is there a SIMPLE x-browser method ? , I have full control of the user environment in this particular case, but obviously x-browser is pfreferable if possible (not including $browsers<V5 !)


<xml src="data_bind_xml.xml" id="xmldso" async="false"></xml>
<script type="text/javascript">
function movenext()
{
x=xmldso.recordset
if (x.absoluteposition < x.recordcount)
{
x.movenext()
}
}
function moveprevious()
{
x=xmldso.recordset
if (x.absoluteposition > 1)
{
x.moveprevious()
}
}
</script>

<a href="javascript:moveprevious()">previous</a> || <a href="javascript:movenext()">next</a>

<br />Name:
<span datasrc="#xmldso" datafld="NAME"></span>
<br />Surname:
<span datasrc="#xmldso" datafld="SURNAME"></span>
<br />Company:
<span datasrc="#xmldso" datafld="COMAPNY"></span>
<br />Http:
<span datasrc="#xmldso" datafld="HTTP"></span>
<br />Email:
<span datasrc="#xmldso" datafld="EMAIL"></span>

jkd
12-21-2002, 04:41 AM
Don't waste time with data binding. There is no such thing as XML islands in the standards, as there are better ways of doing things.

To load an external XML document progmatically, the correct way is:

var doc = document.implementation.createDocument('', '', null);
doc.load('myfile.xml');
doc.addEventListener('load', function(event) {
// do something after the doc has loaded
}, false);

You can accomplish the same in IE by using proprietary ActiveX objects, or you can initialize an XMLHttpRequest in both browsers (a proprietary object both support) and load it that way.

Once it is loaded, you can use DOM methods to extract data.

An even safer way of doing this:

Load the XML file in an iframe. Grab data using DOM methods on its document object, and change its src when needed.

firepages
12-21-2002, 05:44 AM
"Don't waste time with data binding" ... To be honest Jason its already saved me hours of work after 10 minutes of learning that simple bit !

In saying that I am all for learning the right way and a x-browser implementation would be excellent even though not required for this project but I much prefer to write reusable stuff where possible.

With that in mind whats the chance of a quick example of doing what I did above using the DOM and say an iframe ? , even a basic example and I am sure I can workout the rest from there.

pretty please :thumbsup:

jkd
12-21-2002, 12:03 PM
var doc = refToIframe.contentDocument;
var names = doc.getElementsByTagName('NAME');

refToTd.appendChild(document.createTextNode(names.item(0).firstChild.nodeValue));

JoeStone
12-08-2003, 02:36 PM
If I add a level of data to Firepage's XML, can someone tell me how to display all levels?

<?xml version="1.0" encoding="ISO-8859-1"?>
<CONTACTS>
<TEST>Added Level</TEST>
<TEST2>Another Level</TEST2>
<CLIENT>
<NAME>Joe</NAME>
<SURNAME>Blogs</SURNAME>
<COMPANY>JB inc</COMPANY>
<HTTP>http://jb.inc</HTTP>
<EMAIL>jb@jb.inc</EMAIL>
</CLIENT>
<CLIENT>
<NAME>Joanna</NAME>
<SURNAME>Bloggs</SURNAME>
<COMPANY>JBB.inc</COMPANY>
<HTTP>http://jbb.inc</HTTP>
<EMAIL>jbb@jbb.inc</EMAIL>
</CLIENT>
</CONTACTS>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum