BC464Part VIBonus ChaptersImplementation PlanClearly all the data needed (Apache web server)
BC464Part VIBonus ChaptersImplementation PlanClearly all the data needed for numerous sorted and ordered views arrives in one batch fromthe XML file. Despite the element and node referencing properties and methods of the W3CDOM, trying to use the XML elements as the sole data store for scripts to sort the data eachtime would be impractical. For one thing, none of the elements have ID attributes there sno need for it in the XML stored on the server database. And even if they did have IDs, howwould scripts that you desire to write for generalizability make use of them unless the IDswere generated in a well-known sequence? Moreover, after a sales rep s record is rendered inthe table, how easy would it be to dive back into that record and drill down for further infor- mation, such as the name of a representative s manager? A solution that can empower the page author in this case is to use the node-walking proper- ties and methods of the W3C DOM to assemble a JavaScript-structured database while thepage loads. In other words, the conversion is performed just once during page loading, andthe JavaScript version is preserved in an array (of XML records in this case) as a globalvariable. Any transformations on the data can be done from the JavaScript database with thehelp of additional powers of the language. Given that route, the basic operation of the scripting of the page is schematically simple: 1.Convert the XML into an array of objects at load time. 2.Predefine all necessary sorting functions based on properties of those objects. 3.Provide a function that rebuilds the HTML table each time data is sorted. With this sequence in mind, now look into the code that does the job. The CodeRather than work through the long document in source code order, the following descriptionsfollow a more functional order. You can open the actual source code file (salesrpt.htm) to see where the various functions are positioned. To best understand this application, seeing the how rather than the where is more important. Also, many of the code lines (even somesingle expressions) are too wide for the printed page and therefore break unnaturally in the list- ings that follow. Trust the formatting of the source file on the CD-ROM. Style sheetsFor the example provided on the CD-ROM, one set of stylesheet rules is embedded in theHTML document. As you can see from the rule selectors, many are tied to very specificclasses of table-related elements used to render the content. In a production version of thisapplication, I would expect that there would be more and quite different views of the dataavailable to the users, such as bar charts for each salesperson or region. Each view wouldlikely require its own unique set of stylesheet rules. In such a scenario, the proper imple- mentation would be to use the LINK element to bring in a different external stylesheet filefor each view type. All could be linked in at the outset, but only the current styleSheetobject would be enabled.