XML processing in Ajax, part 1th: four methods

Source: Internet
Author: User

Parsing and transforming XML in AJAX programs

Introduction: Any programming problem can be solved by a variety of correct methods. This series examines four ways to create a asynchronous JavaScript + XML (Ajax) Weather Report Panel (weather Badge), a small reusable widget that can be easily embedded into any Web page. This is the first article that introduces some of the basics and examines the first approach-traversing the DOM tree.

The Greek philosopher Aristotle once wrote: "There are many ways to fail ... but there is only one way to success." "Sadly, Aristotle is not a computer programmer," said the man.

Although Aristotle's first assertion conformed to the characteristic of programming-"There are many paths to failure"-his second guess has no basis.

This series of articles employs four methods for the same problem. Each method is proven to be correct-each has its own pros and cons. The problems they are trying to solve are not complicated, and the solution is not complicated. However, these methods involve a large number of "trade-offs" that can be included in a very simple solution.

Problem: Creating a reusable Ajax Weather dashboard

To define the issues that need to be resolved, I have listed the following problem descriptions:

Build an Ajax library to read the latest observational data obtained from National Weather Service, and then extract part of the data and convert it to HTML format to create a weather report panel.

Many web sites like to display local weather conditions on a Web page. To do this, they need access to the latest meteorological information. So how do you get the data?

In the United States, national Weather Service (NWS) provides a great deal of weather information. These include current weather observations from hundreds of cities in the United States. This data can be used in either RSS or XML format.

In Ajax, the letter X represents XML, so NWS data seems to fit well with Ajax methods.

Four Possible solutions

This series of articles examines four different methods for building an Ajax weather panel-A small information box containing meteorological information for any city or town monitored by NWS. Its design goal is

of simplicity

Easy to reuse

I will use these four methods to demonstrate the inherent "trade-offs" of each approach. There is no absolute right or wrong in any of these ways.

Essentially, the implementation of each method is very different, as described in Table 1.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.