AJAX :: Ajax Processing the Atom Feed ::
Processing the Atom Feed When it receives the Atom feed, the LoadAtomFeed function will call the parseAtom function. The following parseAtom function is responsible for picking apart the Atom feed and assigning the pieces to variables. The variables are used by the user interface routines to assemble an HTML page.
items = null;
items_count = 0;
title = null;
link = null;
author = null;
dates = null;
content = null;
function parseAtom( xmldoc) {
items = xmldoc;
items_count=items.getElementsByTagName('entry').length;
title = new Array();
link = new Array()
author = new Array()
dates = new Array();
content = new Array();
for (var i=0; i < items_count; i++) {
title[i] = items.getElementsByTagName('entry
')[i].getElementsByTagName('title')[0];
link[i] = items.getElementsByTagName('entry
')[i].getElementsByTagName('link')[0].getAttribute('href');
dates[i] = items.getElementsByTagName('entry
')[i].getElementsByTagName('updated')[0];
author[i] = items.getElementsByTagName('entry'
)[i].getElementsByTagName('author').firstChild;
content[ i] = items.getElementsByTagName('entry'
)[i].getElementsByTagName('content'
)[0].getElementsByTagName( 'div')[ 0];;
}
}
The way that the Atom feed is parsed is very simple. The XML DOM getElementsByTagName method is used to iterate the elements of the tree. The getElementsByTagName function is chained together so that individual elements can be picked out. The advantage of chaining is that parts of the XML hierarchy can be filtered out to serve as the basis for another filter. This article focused on a new way of building Web applications using SOA. You looked at an example application and learned how to shift into the new architecture based on Ajax and Web services. In your Web application development efforts, keep the following points in mind: • Don’t try to do everything at once. This article showed an approach where you continue using the old database and old data, and incrementally build a new architecture using abstraction and modularization. • The aim of this article is to help you modularize and granularize your Web applications so that there is a client developer, server developer, and database developer. This is not to say you need three developers but when each developer implements a contract, he or she only needs to worry about the contract and not the other pieces. Ideally, all the pieces will be assembled like a jigsaw puzzle. • The server will expose itself as a general Web service adhering to a standard. The standard might be an already developed standard or a standard created within a closed circle. The idea behind developing a standard is to permit the creation of tests that can be used to verify that everything functions correctly. • When using a SQL relational database, you should at all times attempt to stick to the SQL standard so that it is possible to move the data from one database to another. • One of the main reasons for keeping the old architecture side by side with the new is to make it possible to not have to implement all functionality right away. In the example of the blog software, you do not have to implement the functionality to add entries; you can continue using the old software. This allows you to bring your software to market quickly. • You can develop your Web service using standards like SOAP/WSDL, but the example demonstrated the use of REST. REST treats the server-side data as resources that can be manipulated using HTTP verbs (GET, PUT, POST, and DELETE). Think of REST and the HTTP verbs like a SQL database and the manipulation of the data. Remember the purpose of each HTTP verb, so you don’t confuse the end user of your REST Web service. • REST can expose URLs that fit into the following categories: view URLs, root URLs, collection URLs, and data-resource URLs. Make sure in your architecture to clearly define the purpose of each URL and what HTTP verbs it will accept. Failing to do so will confuse the end user of your REST-based Web service. • The Ajax SOA-based client has two distinct phases. The first phase is loading the document. When loading the document, the client is being initialized. During initialization, the client is preparing the code to be executed. The second phase is executing the document, which means the loading and processing of data that is loaded, using Ajax techniques to call aWeb service. This separation of loading and execution is very similar to the loading and execution of a traditional program. • When using XMLHttpRequest, remember to use it for the most part in asynchronous mode. You do not want to lock your browser while waiting for content. Note, however, that asynchronous mode means writing more checking code, as you do not want the client to start clicking buttons while waiting for a request to complete. • The implementation of the Asynchronous and Synchronous classes illustrates the use of mixins to create similar types that have some specialized functionalities. Additionally, the Asynchronous and Synchronous classes show how to implement contracts in JavaScript. • You will want to implement a global error handler in your Ajax application so that any errors that may happen will be displayed in a user-friendly manner. Failing to do so might cause the client to click buttons wildly, and the subsequent reloading of pages will cause even more errors to occur. • When you are processing an XML data stream, take a look at the XML DOM methods to help you pick apart the data. You should not need to iterate each individual node, as XML DOM has great facilities to filter nodes. • The overall message to take away from this article is that by using the approach outlined here, you are moving back to a traditional form of developing client/server applications. The difference is that you are using open standards, which makes it easier to modularize your applications. By using open standards, you make it easier to deploy your application worldwide and easier for third parties to interact with you. In general, this approach to building Web applications is a win-win-win scenario. |
legal disclaimer
Our website is not responsible for the information contained by this article. Web-articles is a free articles resource.
Suggestion: If you need fresh, daily updated content for your website, feel free to use our service. Click here for more information.
related articles
Understanding the Definition and Philosophy of REST REST is a controversial topic among Web service enthusiasts, because it’s considered to stand for the opposite of what Web services and SOA are trying to achieve. The problem with this thinking is that REST is not in contradiction with the abstract definition of SOA and Web services. REST is in contradiction with technologies such as SOAP, WSDL, and WS-* specifications. The following offers a quick definition of REST:...
The Easiest Way to Get Started with Ajax and REST Problem You want to know the best way to get started with writing Ajax and REST. Solution When developing an Ajax and REST application, you must decide on the tools and frameworks you’ll use. The choice is simple: Use whatever you’re using today, and write some Ajax applications. You don’t need to change the tools you’re using today. Whether you’re using ASP.NET, JavaServer Pages (JSP), PHP, Ruby, or Python, you...
3. Testing a Dynamic Contract with Ajax
Coding the Contract Using Test-Driven Development Techniques Coding the contract using agile and test-driven development techniques requires writing a number of tests and implementing aMock URL layer. Problem You want to code the contract using these development techniques. Solution To demonstrate, let’s define a use case, implement the use case as a contract, write a test case(s) to implement the contract, implement the contract in the Mock URL, and finally...
4. Testing the Client Side Logic
Problem You want to effectively test your application’s client-side logic. Theory Testing GUI code tends not to be a productive task because of the complications that arise. The main complication is how to test the correctness of a user interface. Imagine a situation where clicking a button causes a table to be filled with data. Now imagine that when a check box is checked and the button is clicked again, a different table is filled with content. The fact that clicking the same button results in two ...
5. Understanding JavaScript and Types
Understanding JavaScript and Types Problem You want to work around the fact that JavaScript does not have types declared for its variables. Theory JavaScript code does not have any variables with a declared type. The lack of typed variables is apparent when you declare functions. That said, not having typed variable declarations does not mean JavaScript has no types or no type safety. Let’s start out with the simple declaration of a function, as illustrated by the following ex...
6. Coding Using Conventions and Not Configurations
Coding Using Conventions and Not Configurations Problem You want to make your JavaScript constructs more efficient by applying the Rails “convention over configuration” principle to them. Theory You may already be familiar with the programming platform Ruby on Rails, which is used to build Web applications. The focus of this recipe is not Ruby on Rails, but one aspect of Ruby on Rails namely, convention over configuration (see http://en.wikipedia.org/wiki/ Ruby_on_Rails for m...
7. Advantage of parameterless functions in JavaScript
Using Parameterless Functions Problem You want to take advantage of parameterless functions in JavaScript. Theory JavaScript functions for the most part have parameters. You may think that the previous sentence states the obvious after all, without parameters, what data could be passed to a function? JavaScript has the ability to declare functions that have no parameters, even though the caller of the function has passed parameters to the function. For example, let’s look at...
8. JavaScripot Functions
Treating Functions Like Objects Problem You want to take advantage of the fact that functions are objects (remember, everything is an object in JavaScript). Theory Many people think that a function is some keyword used in JavaScript. A function is also an object that can be manipulated. Knowing that a function is an object makes it very interesting from the perspective of writing JavaScript code, because the code can treat the function like another other object. This mean...
9. Implementing an Error and Exception Handling Strategy
Implementing an Error and Exception Handling Strategy Problem You want to implement a clean error and exception handling strategy in your applications, to make them run more smoothly. Theory Of course, you might argue that one error is a dialog box and the other is generated in the JavaScript console. The fact that one browser uses a dialog box to show an error and the other does not is a browser issue, not an error issue. A concise way of classifying the two errors is to ...