XML programming using PHP and Ajax (1)

Source: Internet
Author: User
Tags object sql object model php and wrapper xpath xslt xquery

In an SOA architecture, programmers often use XML to exchange structured and semi-structured data between applications. XML and its related technologies-Document Object Model (Model,dom), XPath, HTTP, XQuery, and Extensible Stylesheet Language Transformations (extensible Stylesheet Language TRANSFORMATIONS,XSLT)-Provides a powerful environment for rapid application development. Applications built on these technologies will consume smaller memory space, require lower maintenance costs, and have higher quality and flexibility.

The XML aspects of DB2 and other relational databases are already quite mature, so they are ideal for storing and managing XML data in addition to storing and managing relational data. DB2 9 XML Support (called PureXML) provides the ability to store XML in the form of pure XML (in other words, annotated, tree-like tiered storage). In DB2 9, XML data can be indexed in XML schemas, can be combined from relational data, can be decomposed into relational data, can be queried and transformed, can be published independently, or combined using sql/xml and XQuery with relational data.

Web browsers are also providing more functionality for client scripts to efficiently process XML. By using asynchronous JavaScript and XML (asynchronous JavaScript and Xml,ajax), Web pages can now make remote procedure calls directly to the application server and can use the DOM APIs on any returned XML data.

This article will show you how to write simple xml-based applications with the capabilities of DB2 XML, Ajax, and PHP hypertext Preprocessor (PHP). With the help of the sample scenario, you will learn how to invoke PHP applications in JavaScript, how to modify XML data using the DOM and SimpleXML APIs, how to transfer XML from the client to the application to the database, and how to create a PHP Web service to use the Sql/xml and XQuery Publish reports about XML data.

XML Benefits

Most applications are used to create, store, manipulate, and render business data. Object wrapping refers to tying business data together so that business logic can handle them more easily. Many of the functions of these wrapper objects are to provide the structure of business data based on relational and formatting rules, and to enable business logic to manipulate, publish, and serialize encapsulated data.

Figure 1. Object Wrapper-based applications

Figure 1 illustrates a sample life insurance application that uses the object wrapper. Each box represents an object, with at least one object:

• A constructor

· Getter and Setter methods

• Validating code

• Serialization of internal object hierarchies

These objects are not related to the actual business logic. Object wrapping is designed to make business logic easier to manage business data. The code needed to wrap the data is much more than the business logic. More code will lead to more bugs, greater retention, more maintenance, and higher costs.

If a data variable in an object can be formatted as an XML structure, and the object's primary role is to expose the data to business logic and let business logic manipulate them, you can replace the object with a DOM.

Figure 2. XML-based applications


Figure 2 shows a sample insurance application that uses the XML and DOM wrappers. All the data wrapper objects in Figure 1 are replaced with a DOM object. Business data is modeled in XML, and the DOM provides the necessary APIs to:

• Create a new XML object.

• Update the value of an XML object.

• Navigating XML objects.

• Search in the object hierarchy using XPath.

• Serialization and drag of the row XML object hierarchy (in other words, built-in persistence).

By using XML, you can avoid using most wrapper objects that manage business data. Applications will become more concise and more focused on business logic than on data management.

XML and schemas

Introducing XML into a schema can provide a standardized way of representing business data. XML can provide the structure of data; XML schemas impose structural and formatting rules, and languages such as the DOM API and XQuery, XPath, and XSLT enable business logic to manipulate, publish, and serialize data efficiently. Because the XML representation of business data is consistent across the client, middle tier, and database, the code that manipulates these objects is similar.

I'll show you how to build an xml-based application in a three-tier environment, which consists of the following parts:

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

• Application Server: PHP and SimpleXML

• Database: DB2 9 and Sql/xml,xquery



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.