XML
  Home arrow XML arrow Page 3 - Widget Walkthrough
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
XML

Widget Walkthrough
By: Dan Wellman
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 2
    2006-08-21

    Table of Contents:
  • Widget Walkthrough
  • Getting the headlines
  • Using loops
  • Fine tuning headline retrieval
  • Publishing your widget

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Widget Walkthrough - Using loops


    (Page 3 of 5 )

     

    The Widget reference manual states that you should use a try catch loop to perform XPath functions, so you can add one to your getData() function.  You will first need to obtain the XML document and place it in a variable using the parse method:

    try {
            doc = XMLDOM.parse(feeddata);

    Next, you need to specify which elements in the XML file you want to match. This is the XPath element of your function:

            titlelist = doc.evaluate( "rss/channel/item/title" );
            datatextarea.data = "";

    You now need to create an array to hold the headlines as separate DOMElement objects:

            titles = new Array();

    In this particular rss file, there are always 19 headlines, however, if you were using a different feed, you may not know the number of headlines in advance so it is a good idea to use a for loop that operates on the length of your array:

            for (n = 0; n < titlelist.length; n++) {

    The DOMNodeList returned by the XPath function has a built-in property of item() which can be used to specify which DOMElement in the list you are referring to. In this case, we can match the number of the array item with the item we want to store in the array:

              titles[n] = titlelist.item(n);

    Finally, each time the loop iterates, you can set the data property of the <textarea> to the data held in the array item. The actual item held in the array is the DOMElement; to get the actual text held in the object you need to address the firstChild of the element.  The JavaScript new line character is also specified (twice) to break up the headlines:

              datatextarea.data += titles[n].firstChild.data + "nn";
            }
        }
          catch(e) {
            print(e);
        }

    More XML Articles
    More By Dan Wellman


       · Hi, hope you enjoy finishing off the example widget and that you are inspired to...
     

    XML ARTICLES

    - Using Regions with XSL Formatting Objects
    - Using XSL Formatting Objects
    - More Schematron Features
    - Schematron Patterns and Validation
    - Using Schematron
    - Datatypes and More in RELAX NG
    - Providing Options in RELAX NG
    - An Introduction to RELAX NG
    - Path, Predicates, and XQuery
    - Using Predicates with XQuery
    - Navigating Input Documents Using Paths
    - XML Basics
    - Introduction to XPath
    - Simple Web Syndication with RSS 2.0
    - Java UI Design with an IDE







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek