Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts

    data-binding:: scrolling though XML records howto ?

    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.....
    Code:
    <?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>
    Code:
    <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>
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    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 !)

    Code:
    <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>
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    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.

  • #4
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    "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
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #5
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    var doc = refToIframe.contentDocument;
    var names = doc.getElementsByTagName('NAME');

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

  • #6
    New Coder
    Join Date
    Apr 2003
    Location
    Dallas
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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>


  •  

    Posting Permissions

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