XML programming using PHP and AJAX

Source: Internet
Author: User
In SOA architecture, programmers often use XML to exchange structured and semi-structured data between applications. XML and related techniques-DocumentObjectModel, DOM, XPath, HTTP, XQuery, and extensible style sheet language conversion

In SOA architecture, programmers often use XML to exchange structured and semi-structured data between applications. XML and related techniques-Document Object Model (DOM), XPath, HTTP, XQuery, and extended style sheet Language conversion (Extensible Stylesheet Language Transformations, XSLT) -It provides a strong environment for rapid use of program development. The exploitation program built on these skills will occupy less memory space, requiring lower protection costs, and having higher moral character and mobility.

The XML features of DB2 and other relational databases are quite mature. Therefore, apart from the storage and governance of relational data, they are also the fantasy choice to store and manage XML data. DB2 9 XML support (called pureXML) provides a pure XML situation (in other words, it is a layered storage with annotation, tree) to store XML. In DB2 9, XML data can be indexed in XML mode and combined into relational data. it can be divided into relational data, queried and converted, and can be independently announced, alternatively, you can combine SQL/XML and XQuery with relational data.

Web browsers are also providing more functions for client scripts to effectively process XML. By applying Asynchronous JavaScript and XML (Asynchronous JavaScript and XML, Ajax), Web pages can now directly call the process using the server, and can apply DOM APIs to any returned XML data.

This article will show how to use the functions provided by DB2 XML, Ajax and PHP Hypertext Preprocessor (PHP) to write a simple XML-based application. With the help of the example scenario, you will learn how to call PHP Exploitation programs in JavaScript; how to apply DOM and SimpleXML APIs to modify XML data; how to transfer XML from the client to the application and then to the database; and how to create a PHP Web service to apply SQL/XML and XQuery to announce the XML data report.

  XML strengths

Most exploitation programs are used to create, store, control, and expose business data. Object packaging means to bind business data together so that the business logic can process them more easily. Many of the functions of these wrapper objects are the structures that supply business data according to the relationship and pattern rules, and enable the business logic to control, announce, and serialize the encapsulated data.

Figure 1. Exploitation program based on object wrapper
  

Figure 1 illustrates a sample life insurance exploitation program for the application object package. Each box represents an object. each object must have at least:

· A structure function

· Getter and Setter methods

· Verification code

· Serialization of internal object layers

These objects have no relationship with the actual business logic. Object packaging aims to make business logic more easily manage business data. Data packaging requires much more code than business logic. More code will lead to more bugs, greater fixation, more protection and higher costs.

Assume that the data variables in the object can be structured into XML structures, and the important role of the object is to expose the data to the business logic and let the business logic hold them, you can replace the object with DOM.

Figure 2. XML-based exploitation program
  

Figure 2 shows an example insurance exploitation program that uses XML and DOM wrappers. All data wrapper objects in figure 1 are replaced by a DOM object. Business data is modeled in XML, and DOM provides the necessary APIs:

· Create a new XML object.

· Update the value of the XML object.

· Navigation XML object.

· Apply XPath to search at the object level.

· Serializing and deserializing XML object layers (in other words, built-in persistence ).

By applying XML, you can avoid most application wrapper objects used to govern business data. Exploitation programs will become more concise and focus more on business logic, rather than data governance.

  XML and architecture

When XML is introduced into the architecture, it can be considered as a standard method for displaying business data. XML can provide the structure of data; XML mode applies structure and pattern rules; DOM APIs and languages such as XQuery, XPath, and XSLT allow business logic to effectively control, declare, and serialize data. Because the XML of business data is consistent in the client, middle layer, and database, the code for holding these objects is similar.

I will show you how to build XML-based exploitation programs in a three-tier environment, which consists of the following parts:

· Web Client: Asynchronous JavaScript and XML (Ajax), DOM

· Servers used: PHP and SimpleXML

· Database: DB2 9, SQL/XML, and XQuery[1] [2] [3] [4] Next page 

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.