Listing 3-5 shows a quick and rough [13] solution to achieve this particular requirement. This example uses PHP and MySQL databases, but our focus is on the overall structure. If you change to ASP, JSP, or Ruby script, you may get code that is similar in structure.
Code listing 3-5 generates XML data streams quickly and with the result of database query results
The PHP page in Listing 3-5 generates an XML page similar to code listing 3-6, in which there are two matching products in the database. Here, the code is indented to make it easier to read. XML is chosen as the medium of communication between the client and the server because it is usually used for this purpose, and the 2nd chapter also mentions how to use the Xml-httprequest object to process the server-side generated XML document. The 5th chapter will explore the other options for client and server communication in more detail.
Code Listing 3-6 Code listing 3-5 output Simple XML
We have a Web server-side application that assumes a good AJAX application at the front end to handle this XML. To look forward to the future. Let's say you want to add subcategories (such as fashion, casual wear, outdoor sportswear) as the product range expands, add the "season Search" feature, implement keyword search, and clear links to entries. All of these features can be well supported by similar XML data streams. Let's look at how to reuse the current code to achieve these goals and what obstacles will be encountered in the process.