Practical tips for XML volumes (2): dynamic query

Source: Internet
Author: User
The query function is the most common and commonly used function module we have seen on the website. In the past, all information queries were connected to the database, and each click must be supported by the background database. However, in many cases, users only operate on a certain part of the data, which not only increases the server load, but also seriously affects the user's browsing speed. Motivation:
The query function is the most common and commonly used function module we have seen on the website. In the past, all information queries were connected to the database, and each click must be supported by the background database. However, in many cases, users only operate on a certain part of the data, which not only increases the server load, but also seriously affects the user's browsing speed.

In this case, we need to pass a part of the data that the user needs to the client in XML format, which can be easily operated by the user. It not only facilitates users, but also reduces the burden on the server database. Why not! This function can be used in many other modules. Therefore, this dynamic query function is added.

Materials:
Dynamic query of XML volumes
There are two files: search. xml and search. xsl.

Purpose:
Filter and filter data without refreshing the page, which effectively improves the Data Query function.
Effect:
Browse here
Code:
Search. xml

 
 
   
      
   
    
1
       
   
    
Sailflying
       
   
    
A simple query
       
   
    
2002-1-11 17:35:33
       
   
    
XML topics
     
    
      
   
    
2
       
   
    
Flyingbird
       
   
    
Marry you. it hurts you.
       
   
    
2001-09-06 12:45:51
       
   
    
Irrigation essence
     
    
      
   
    
3
       
   
    
Accounts
       
   
    
Application of regular expressions in UBB forum
       
   
    
2001-11-23 21:02:16
       
   
    
Web Programming Essence
     
    
      
   
    
4
       
   
    
Taiyilang
       
   
    
End-of-year classic rudder gathering full manual v0.1
       
   
    
2000-12-08 10:22:48
       
   
    
Forum irrigation area
     
    
      
   
    
5
       
   
    
Mmkk
       
   
    
Asp error message summary
       
   
    
2001-10-13 16:39:05
       
   
    
Javascript script
     
  
 


Search. xsl

 
 
  
   Practical tips for XML volumes (2): dynamic query
   Script function searchtext (x) {stylesheet = document. optional document; source = document. XMLDocument; sortField = document. invalid document. selectNodes ("// @ select"); if (x! = "") {SortField [1]. value = "team [blue_ID = '" + x + "']" ;layer1.innerhtml#source.doc umentElement. transformNode (stylesheet);} else {alert ("Enter filtering conditions! ") ;}} Script
   

Practical tips for XML volumes (2): dynamic query

Enter the filtering condition: blue_ID =
No. Name Topic Posting time Category


Explanation:
1) search. xml is a data file, and we believe there will be no problem.
2) search. xsl is a format file. There are several points to note.
(1) in the script:

sortField=document.XSLDocument.selectNodes("//@select");

The role is to find all nodes with the select attribute. This is what I mentioned in dynamic sorting.

sortField=document.XSLDocument.selectSingleNode("//@order-by");

There are some differences. Pay attention to this small difference and their respective functions.


sortField[1].value="team[blue_ID='"+x+"']";

Therefore, sortField [1] is the second node, and its corresponding node is

 

Parameter x is the value entered in the text box.
Modify the search condition of select = "team" to select = "team [blue_ID = 'x']"
The function is to add judgment conditions. only XML data with the value of blue_ID equal to x is displayed.
Of course, you can enrich the judgment conditions. The simple judgment I made here is to make it easier for everyone to understand.
Finally, the new sorting content is displayed by re-displaying the innerHTML value of Layer1.

(2) text:

Select = "team"
Here it is sortField [1], but it may be changed when you do it.
So you must calculate the accuracy!
I provide a common method: in the code, you can use loops to determine whether the node is required for you.


Another point:
XML has extremely strict requirements on case sensitivity. If your writing is not standard, it will catch a cold!

Postscript:
After you are familiar with the dynamic sorting and dynamic query completion ideas, you will find that our implementation method is very simple.
Is to modify a value, and then re-display.
We still follow this idea in the dynamic paging function.

The above is the practical experience of XML volumes (2): the content of dynamic query. For more information, see PHP Chinese network (www.php1.cn )!

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.