advertisement
Premier Club Log In/Registration
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   SKILLBUILDING  |   TIP BANK  |   SOURCEBANK  |   FORUMS  |   NEWSLETTERS
Browse DevX
Partners & Affiliates
advertisement
advertisement
advertisement
Average Rating: 3.2/5 | Rate this item | 25 users have rated this item.
 

Traverse XML Data Using JavaScript

Learn how to build a JavaScript app that reads data from external XML files, traverses that data, and then displays it in a tree format.  


advertisement
n this article, I'll show you how to build an XML-based, client-side JavaScript app that reads data from external XML files, traverses the XML data, and displays that data in a tree format. The sample code uses the XMLDOM ActiveX object built into Microsoft Internet Explorer.

Say you have the following personal data and you want it displayed in a structured manner:

  • name: Premshree Pillai
  • sex: male
  • Websites: Websites
  • ws1: http://www.qiksearch.com
  • ws2: http://premshree.resource-locator.com
The XML looks like this:

<?xml version="1.0"?>
<personal>Personal Details
        <name>Premshree Pillai</name>
        <sex>male</sex>
        <websites>Websites
                <ws1>http://www.qiksearch.com</ws1>
                <ws2>http://premshree.resource-locator.com</ws2>
        </websites>
</personal>
This is the algorithm you'd use:
  1. Read the XML file
  2. Point a variable, tree to the first node (XML tag) of the XML data.
  3. If the node has child nodes:
    • Print "<ul><li>";
    • For each child node, traverse(tree.childNodes(nodeNum))
    • Print "</li></ul>";
  4. If the node does not have any child:
    • Print the node's value.
  Next Page: The Script
Page 1: IntroductionPage 3: What the Script Does
Page 2: The Script  
Please rate this item (5=best)
 1  2  3  4  5
advertisement
Advertising Info  |   Member Services  |   Permissions  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs