Detailed explanation of code examples for creating address book through XML data island and Dom

黄舟
Release: 2017-03-25 10:36:08
Original
1462 people have browsed it

Generally, if you want to provide an address book program for a website, you need to use CGI combined with background database technology. This has relatively high requirements for the WEB server and cannot even be implemented on many virtual hosts that do not provide database functions. Of course, we can also use TXT text to replace the database, but TXT text is more difficult to operate. We must read and judge line by line, and also use delimited strings to separate fields, and complex operations cannot be performed.
Now, we can use "Extensible Markup Language (xml)" to save address book data, thus reflecting the advantages of XML: a structured method of expressing data, which is very useful for saving files with many relational data structures. help.

1. Basic principles:
In Microsoft Internet Explorer 5.0 and later versions, we can use XML elements to create data islands. Data islands are XML data that are referenced or included in HTML pages. XML data It can be included in an HTML file or in an external file. Using XML data islands can save us from the trouble of writing complex scripts. DOM can parse XML documents. All elements, entities, attributes, etc. in the document can be represented by an object model. The logical structure of the entire document is similar to a tree. The generated object model is the node of the tree. Each object also contains In addition to methods and attributes, DOM provides many methods for finding nodes. Using DOM, developers can dynamically create XML, traverse documents, and add (delete/modify) document content. The API provided by DOM has nothing to do with programming languages, so there are no clearly defined interfaces in some DOM standards, and the implementation methods of different parsers May vary.

2. The specific process is:
1. Define the XML file as follows:

     <中国计算机世界出版服务公司通信录>       <计算机世界 contactID="2">         <部门名称>计算机室         <电话号码>139         <电子邮件>fsdos@163.net            
Copy after login

Save the above XML document as a tele.xml file, and at the same time, save the above XML document as Leave the field content blank as initialization frame data and save it as a newid.xml file.
2. The client loads the XML document and binds the XML file to the table through DATASRC='#xmldso' in the table where the address book is placed. The DATASRC attribute is actually passed through the ID attribute of the XML element to be processed. This is achieved by adding # in front, so we can specify the specific fields that need to be displayed in the middle of the TD element;
3. Use DOM technology to add and delete records in the address book;
4. Connect to the address book through the xmlhttp protocol Server, saves XML documents.

3. Brief description of XML DOM programming:
1. Client dom.htm page:

      
计算机世界----通信录

编号部门名称电话号码电子邮件
Copy after login

2. The server-side dns2.asp program is relatively simple. After receiving the XML data , create a file object and save it to tele.xml:

< Set ReceivedDoc = CreateObject("Microsoft.XMLDOM") '创建 XML DOM实例; ReceivedDoc.async=False ReceivedDoc.load Request '接收XML数据; Set files=Server.CreateObject("Scripting.FileSystemObject") Set numtxt=files.CreateTextFile(Server.MapPath("tele.xml"),True) numtxt.WriteLine(replace(ReceivedDoc.xml,"?>"," encoding=""gb2312""?>")) '将XML数据写入文件 numtxt.Close response.write ReceivedDoc.xml >
Copy after login

3. During actual use, you also need to add a web page index.htm that displays the address book, which is actually a simplified version of the above dom.htm. Remove all add, delete, modify and save functions, and only use LABEL to display data in table cells:

  
计算机世界----通信录

编号部门名称电话号码电子邮件
Copy after login

4. Advantages of using XML data island combined with Dom technology:
1. First of all, of course XML itself brings benefits. XML breaks the monopoly of tag definitions. You can customize field names. In the XML file used in this article, even the field names can be in Chinese. The data is very simple and clear, because the information it carries is not a description on the display, but a description on the display. It is the semantic meaning of the information, which greatly enhances the readability of the document. Using XML also facilitates the transfer of information between different systems.
2. XML data island allows users to access and manipulate data sets on the client without frequent interaction with the server, which is very helpful in reducing the load on the server. At the same time, due to the characteristics of the XML data island itself, data operations on the client are very simple and the amount of programming is reduced.
3. DOM forces the use of a tree model to access information in XML documents. Since XML is essentially a hierarchical structure, this description method is quite effective. Through the DOM interface, the application can access any part of the data in the XML document at any time, and the control is quite flexible.
4. Use the xmlhttp object to transmit XML data to the server, and the client page will refresh without flickering.

This program runs successfully on IIS5.0 and IE5.0 based on Windows2000 platform. In the actual application process, you can also use DOM combined with XSL technology to add functions such as sorting, format conversion, and data search to the address book. Use the datapagesize attribute of the XML data island and the PReviousPage and nextPage functions to add paging functions to the address book. Use DTD and XML Schema dynamically validates address book data.

------------------------THE END------------------ ----

Attachment: (all source programs)
****************************** **********************************************
one , index.htm (display address book):

  
计算机世界----通迅录

编号部门名称电话号码电子邮件
Copy after login

********************************** *******************************************

two , dom.htm (online editing address book):

     
计算机世界----通信录

编号 部门名称 电话号码 电子邮件
Copy after login

******************************** ************************************************

3. dns2.asp (save address book in the background):

<% Set ReceivedDoc = CreateObject("Microsoft.XMLDOM") ReceivedDoc.async=False ReceivedDoc.load Request Set files=Server.CreateObject("Scripting.FileSystemObject") Set numtxt=files.CreateTextFile(Server.MapPath("tele.xml"),True) numtxt.WriteLine(replace(ReceivedDoc.xml,"?>"," encoding=""gb2312""?>")) numtxt.Close response.write ReceivedDoc.xml %>
Copy after login

************************************ *********************************************

4. tele.xml (address book XML document):

 <中国计算机世界出版服务公司通信录> <计算机世界 contactID="1"> <部门名称>电话总机 <电话号码>010-68130909 <电子邮件>webmaster@ccw.com.cn  
Copy after login

****************************************************************************

五、newid.xml(通讯录XML初始化文档):

 <中国计算机世界出版服务公司通信录> <计算机世界 contactID="1"> <部门名称>尚未输入 <电话号码>保密 <电子邮件>保密  
Copy after login

以上就是用XML数据岛结合Dom制作通讯录的代码实例详解的内容,更多相关内容请关注PHP中文网(m.sbmmt.com)!

相关文章:

php实现在线通讯录功能(附源码),通讯录源码

详解HTML5通讯录获取指定多个人的信息的示例代码

js实现做通讯录的索引滑动显示效果和滑动显示锚点效果

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!