Widget Initialization Using JSON, HTML Custom Tags and XML Files [con't]
Here, as in the previous example, the list definition contained in the XML file has to be parsed after the page has loaded, and an object representation of the list is obtained. After that it's shown by calling the
Defensive programming is a technique aimed at reducing errors, in spite of the application overhead. When declaring a widget, here are some things to check to assure a stable application:
- Calculated Values: In our examples, the list widget is programmed to fit 100% of its container. Therefore, the sum of all columns must be 100. Checking this calculated value is recommended to avoid strange behaviors.
- Parsing XML/HTML Tags
HTML Custom Tags and XML tags aren't parsed the same way as you can observe in the examples. HTML is parsed using the HTML Parser and XML using the XML parser. IE data islands (
<xml>tag that indicates that the content inside it is handled by MSXML XML parser instead of the HTML parser) weren't considered as in this article as a cross-browser approach was required.
- Viewing Examples
When running examples, be sure you run them within the http: protocol as they might not work running on local files (file: protocol) due to your security policies.
NOTE: Some helper functions were not included in the article for clarity reasons. A complete working example is available for downloading.
This article showed various ways to configure DHTML widgets, from non-recommended ones to better solutions involving JSON and XML files. It also showed how inexperienced developers can easily configure widgets since the widget framework will warn them, via alert messages, what is missing. These techniques are focused to avoid errors and speed up development time, and what you decide to implement, will depend on the needs of your development team needs and their skill level.
About the Author
Nicolas Erlijman is a System Engineer specialized in web technologies working at Tata Consultancy Services, Asia's biggest IT Company. For more information, visit http://www.tcs.com.
Original: January 17, 2007