Example drill ASP+XML programming
This article is an example article. As an ordinary programmer, I know very well how helpful a good routine is to those who are learning programming. The routine used in this article is a contact information management program, which I also wrote to facilitate contact with my friends. But although the sparrow is small, it is complete with all organs. I believe that it still has certain reference value for friends who are learning ASP+XML programming.
Readers can use this example to understand how to manipulate XML files in ASP (ActiveServerPage) and perform various data processing, including the establishment, modification, deletion and saving of XML nodes, etc. The technologies involved in the article include ASP, VBScript, DOM, XML and XSL.
This article does not provide an in-depth theoretical introduction to the technologies used, so readers need to have a certain amount of relevant knowledge, especially ASP, XML and DOM. Read through this article and refer to the source code, I believe readers can master XML programming proficiently.
1. Procedure description
The routine is based on the B/S structure, and uses an XML file to store contact information, and then uses a Class written in VBScript to perform various operations on the contact information in the XML file.
The code provided by routines adopts a unified naming specification, mainly including: using three letter abbreviations to illustrate variable types, such as numeric types - int, string types - str, object - obj, etc. Although in ASP/VBScript, data types are not distinguished, it is still very meaningful to use obvious data types to describe the program; using meaningful variable names, such as XMLDocument objects, defined as objXmlDoc, etc. Similarly, this is also done to better write and maintain the program.
This program can be divided into two parts: background data processing and front-end interface performance.
The program background, written a Class using VBScript, which is a new feature provided in VBScript version 5.0. Although the concept of Class here is far from the true object-oriented, the rational use of Class in ASP can still improve the operation efficiency and maintainability of the program to a certain extent.
The front-end performance uses XSL to format the data in the XML file and then output it to the client in HTML, fully reflecting the flexibility and customizability brought by XML technology. The formatting process is placed on the server side and completed using the ASP program. In this way, the client gets the formatted HTML information, which avoids the occurrence of compatibility issues.
Of course, the program does not conduct very strict inspections on specific operation details, such as checking the required contact information, but for the relevant parts of using DOM to operate XML in ASP, the program provides complete sample code.
2. XML file description (persons.xml)
The XML file used in routines is very simple in structure and does not define the relevant schema or DTD because this is unnecessary for this program. Of course, if readers are willing to define one by themselves, it will not affect the operation of the program.
The data structure of the program is defined as the Persons collection, which contains multiple Person objects, each Person object includes the attributes of the name Name, English name Nick, mobile phone, Tel, email email, Tencent QQ and company. Correspond to the XML file, namely, Person is the root node, Person is the child node of Persons, and Name, Nick, Mobile, Tel, Email, QQ and Company are the child nodes of Person.