O'Reilly logo

JavaScript® Bible, Seventh Edition by Paul Novitski, Danny Goodman, Tia Gustaff Rayl, Michael Morrison

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 60. Application: Transforming XML Data

IN THIS CHAPTER

  • Mapping XML data to JavaScript objects with Ajax

  • Complex JavaScript data structures

  • Advanced array sorting

  • Dynamic tables

Chapter 55, "Application: Outline-Style Table of Contents," ends with an example of an interactive outliner whose data arrives from an external XML file, a feature supported by modern browsers. The application described in this chapter picks up from there.

As you recall from the Chapter 55 outline, the node structure of the XML data was used as a guide to the structure for a one-time rendering of HTML elements. There was a one-to-one correlation between XML element nesting and the HTML element nesting. Adjusting style sheet properties for displaying or hiding elements controlled all interactivity. What you're about to see here is a case for converting XML into JavaScript objects that can be used multiple times, as a convenient data source for HTML that is displayed in any number of formats. In particular, you see how JavaScript's array-sorting prowess supplies XML data with extraordinary flexibility in presentation.

You will see a lot of code in this chapter. The code is presented here as a way to demonstrate the potential for rich data handling. At the same time, the code may provide ideas for server-side processing of XML data being output to the client.

Application Overview

Understanding the data is a good place to start in describing this application. The scenario is a small American company (despite its ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required