AJAX and using E4X to write Web service scripts (1)

Source: Internet
Author: User

This article first briefly introduces ECMAScript (ECMAScript for XML, E4X), which can be used for XML. It is a simple extension of JavaScript, which makes writing XML scripts very simple. In this article, the author demonstrates a Web programming model called Asynchronous JavaScript and XML (Asynchronous JavaScript and XML, AJAX, it also shows you how some new XML extensions of JavaScript make it easier to implement.

ECMAScript for XML

You may not have encountered this term ECMAScript before. It is actually the official name of JavaScript. European Computer Manufacturers Association (ECMA) is a standardization organization that develops JavaScript standards (C # And CLR standards are also developed by the Association ). ECMAScript standards can be obtained from ECMA Web sites for free.

E4X is an extension of JavaScript. In fact, it adds direct support for XML in JavaScript. It is also an ECMA standard (see references-ECMA-357 ). So what is its direct support for XML? Why is it of high value? If you are a JavaScript programmer, you may have used Netscape LiveConnect or Rhino (™To use these Java libraries in your JavaScript. This means that you can create, operate, and use XML with the help of the XML library. Similarly, if you use Microsoft®Internet Explorer, you have obtained XML support through the Microsoft MSXML2 library. In this case, if you have used those library files, make preparations for important changes-E4X is simpler and easier than them.

Before viewing the sample instance, note that E4X has two available implementation methods. The two available methods are from Mozilla. One is the C JavaScript engine used by the browser (it is the SpiderMonkey named by code), and is available in the latest Mozilla version-we use Mozilla 1.8a6. E4X is also available in Rhino. Rhino is a Java built-in JavaScript interpreter and Compilation Program. We will demonstrate its independent use and running in Axis. Both can be obtained from Mozilla.

In these sample instances, we first start from using E4X on the Rhino command line, then turn to using E4X inside the Mozilla browser, and demonstrate the AJAX model. In the second article, we will show you how to embed Rhino into the Apache Axis Web service engine to use E4X inside the server. However, before we turn to Web services, we will first show you the XML programming basics in E4X.

A simple example

We start with a simple instance. First, we analyze and operate the XML that represents the author's relevant information. The XML we want is as follows:

Listing 1. Author's XML document



Ant
Shaggy
Blue
176


Paul
Spiky
Grey
178

If we get the XML document in the form of a string, we can "parse" the string using the following simple operations:

Var x = new XML (lelexmlstring );

In addition, we can simply "embed" the XML into the Code:

Var x =


Ant
Shaggy
Blue
176


Paul
Spiky
Grey
178

;

Yes -- this is correct -- XML becomes a direct part of this language.


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.