Using the Interactive Website Framework to Handle XML


The Interactive Website Framework (IWF) is another framework that specializes in handling XML, and also has Ajax capabilities built in.

On the Web 

You can get IWF for free at http://sourceforge.net/projects/iwf/.

This framework allows multiple XMLHttp requests at the same time, and prevents caching by sending unique URLs to the server. Its custom XML parser can make it easier to handle XML, so that you can extract data from an XML document using syntax like this in JavaScript:

 var dressing = doc.pizza.topping[0].dressing;

instead of something like this:

 var dressing = doc.documentElement.firstChild .getAttribute("dressing");

Cross-Ref  

See Chapter 9 for more information on extracting XML data from XML documents using JavaScript.

IWF gives you many built-in tools, such as functions that let you move elements around a Web page to support drag-and-drop operations, or functions that let you grab XML data and insert it into an HTML element in a Web page.

Here’s an example. You need to use certain XML elements to work with IWF, as in this XML docu

ment, iwf.xml:

 <?xml version="1.0" ?> <response>   <action type='html'>     This text was downloaded using IWF.   </action> </response>

The example page, testIWF.html, downloads and extracts the text in this document. Start with a button, connected to a function named useIWF:

 <input type = "button" value = "Display the text"   onclick = "useIWF()"> </form>

Instead of the usual <div> element, give the <div> element in this page a special name-iwfContent-which is the name IWF will look for:

 <input type = "button" value = "Display the text"   onclick = "useIWF()"> </form> <div id='iwfContent'>The fetched text will   appear here.</div> 

Then include the IWF JavaScript libraries, iwfcore.js, iwfxml.js, and iwfajax.js:

 <html>   <head>      <title>Testing IWF</title>      <script src='/books/1/252/1/html/2/iwfcore.js'></script>      <script src='/books/1/252/1/html/2/iwfxml.js'></script>      <script src='/books/1/252/1/html/2/iwfajax.js'></script>          .          .          . 

The rest is easy. Just call the iwfRequest function, passing it the URL to download, like this:

 <html>   <head>     <title>Testing IWF</title>     <script src='/books/1/252/1/html/2/iwfcore.js'></script>     <script src='/books/1/252/1/html/2/iwfxml.js'></script>     <script src='/books/1/252/1/html/2/iwfajax.js'></script>     <script>       function useIWF()       {         iwfRequest('iwf.xml')       }    </script> </head>

When iwf.xml is downloaded, IWF unpacks the data itself and displays it in the HTML element that has the ID iwfContent. That’s all there is to it. You can see this page at work in Figure 6.10.

image from book
Figure 6.10: Downloading XML with the IWF framework



Ajax Bible
Ajax Bible
ISBN: 0470102632
EAN: 2147483647
Year: 2004
Pages: 169

Similar book on Amazon
HTML, XHTML, and CSS Bible
HTML, XHTML, and CSS Bible
JavaScript Bible
JavaScript Bible
JavaScript Bible
JavaScript Bible
PHP and MySQL Web Development (4th Edition)
PHP and MySQL Web Development (4th Edition)

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net