How to query XML code by ASP without refreshing a new page

Source: Internet
Author: User

Reference content is as follows:
<HTML>
<Head>
<Title> Method for querying a new page </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
</Head>
<Script language = "JavaScript">
<! -- Initialize and load the data in the data island to the list box -->
Function loadinsel ()
{
VaR employeeid, employeelastname; // store the employee ID and employee name respectively.
Root = Document. All. xmlemployees. childnodes. Item (0); // returns the first element -- employee
For (I = 0; I <root. childnodes. length; I ++ ){
Getnode = root. childnodes (I); // obtain a subnode of empolyee.
Employeeid = root. childnodes (I). getattribute ("emid"); // obtain the employee ID
For (j = 0; j <getnode. childnodes. length; j ++ ){
Employeeinf = getnode. childnodes (j). nodename;
If (employeeinf = "lastname "){
Employeelastname = getnode. childnodes (j). Text; // get the employee name
}
}
// Write the obtained employeeid and employeelastname into the SELECT statement.
If (employeeid! = "" & Employeelastname! = ""){
Option1 = Document. createelement ("option ");
Option1.text = employeelastname;
Option1.value = employeeid;
Employeelist. Add (option1 );
}
}
}
<! -- Initialize, retrieve data from the data island, and load the data in the list box -->
Function findemployee (){
VaR employeelastname, employeeid; // store the employee name and employee ID respectively.
Employeelastname = "";
Employeeid = "";
Findtext = Window. findcontent. value; // obtain the search condition.
// Clear the list box
Employeecount = employeelist. Length
For (I = employeecount-1; I> = 0; I --){
Employeelist. Remove (I );
}
Root = Window. xmlemployees. childnodes (0 );
For (I = 0; I <root. childnodes. length; I ++ ){
Getitem = root. childnodes (I); // obtain a subnode of empolyee.
Employeeid = root. childnodes (I). getattribute ("emid"); // obtain the employee ID
For (j = 0; j <getitem. childnodes. length; j ++ ){
If (getitem. childnodes (j). nodename = "lastname "){
Employee_temp = getitem. childnodes (j). text;
If (employee_temp.indexof (findtext )! =-1) {// search for matching items
Employeelastname = employee_temp; // locate the employee whose name matches
}
}
}
// Write qualified employee information into select
If (employeeid! = "" & Employeelastname! = ""){
Option1 = Document. createelement ("option ");
Option1.value = employeeid;
Option1.text = employeelastname;
Window. employeelist. Add (option1 );
Employeeid = "";
Employeelastname = "";
}
}
}
</SCRIPT>
<Body bgcolor = "# ffffff" text = "#000000" onLoad = "javascript: loadinsel ()">
<Table width = "80%" border = "1">
<Tr>
<TD> enter the query conditions:
<Input type = "text" name = "findcontent">
<Input type = "button" name = "Submit" value = "Search" onclick = "javascript: findemployee ()">
</TD>
</Tr>
<Tr>
<TD> query result:
<Select name = "employeelist">
</SELECT>
</TD>
</Tr>
</Table>
<? XML version = "1.0" encoding = "gb2312"?>
<%
Servername = "WYB" 'server name
User = "sa" 'User Name
PW = "" 'User Password
Databasename = "northwind" 'Database Name
Set conn = server. Createobject ("ADODB. Connection ")
Conn. Open "driver = SQL Server; server =" & servername & "; uid =" & user & "; Pwd =" & PW & "; database =" & databasename
Set rs = server. Createobject ("ADODB. recordset ")
SQL = "select employeeid, lastname from employees order by employeeid"
Rs. Open SQL, Conn %>
<! -- Put the information in the database into the data island -->
<XML id = "xmlemployees">
<Employee>
<% Do while not Rs. EOF %>
<Employeeitem emid = "<% = RS (" employeeid ") %>">
<Lastname> <% = RS ("lastname") %> </lastname>
</Employeeitem>
<% Rs. movenext %>
<% Loop %>
</Employee> </XML>
<% Rs. Close
Set rs = nothing
%>
</Body>
</Html>
Use the instr () function of ASP to check whether the string contains the specified string.
<%
Dim wstr1, wstr2
Wstr1 = "Hello world! "
Wstr2 = "O"
If instr (wstr1, wstr2)> 0 then
Response. Write ("" & wstr1 & "" & wstr2 &"")
Else
Response. Write ("" & wstr1 & "does not contain" & wstr2 &"")
End if
%>
--------------------
Instr Functions
--------------------
Instr ([start,] string1, string2 [, compare])
[Parameters]
The syntax of the instr function has the following parameters:
Part
Description
Start
Optional. It is a numeric expression that specifies the start point of each search. If omitted, it starts from the first character. If start contains null, an error occurs. If the compare parameter is specified, the start parameter is required.
String1
Required parameter. String expression to be searched.
String2
Required parameter. String expression to be searched.
Compare
Optional. String comparison. If compare is null, an error occurs. If compare is omitted, the option compare setting determines the comparison type.
? The compare parameter is set:
Constant
Value
[Description]
Vbusecompareoption
-1
Use the option compare statement to execute a comparison.
Vbbinarycompare
0
Execute a binary comparison.
Vbtextcompare
1
Execute a comparison based on the original text.
Vbdatabasecompare
2
For Microsoft access only, perform a comparison based on the information in the database.
[Return value]
Returns 0, 1, 2,-1, or null.
[Exception/Error]
None
Description instr ([start,] string1, string2 [, compare])
Returns the first occurrence position of a specified string in another string. In the string1 string, find string2 from start and start from string1 if start is omitted. If no value is found, the function value is 0.
If
Instr return
String1 0 Length
0
String1 is null
Null
String2 0 Length
Start
String2 is null
Null
String2 not found
0
Find string2 in string1
Location found
Start> string2
0
[Example]
In this example, the instr function is used to find the position where a string first appears in another string.
Dim searchstring, searchchar, Mypos
Searchstring = "xxpxxpxxpxxp.
Searchchar = "p" 'to search for the string "p ".
'Start from the fourth character and start with text comparison. The return value is 6 (lower case P ).
'Lower-case P and upper-case P are the same in text comparison.
Mypos = instr (4, searchstring, searchchar, 1)
'Start with the first character and start with binary comparison. The return value is 9 (uppercase P ).
'Lowercase P and uppercase P are different in binary comparison.
Mypos = instr (1, searchstring, searchchar, 0)
'The default comparison method is binary comparison (the last parameter can be omitted ).
Mypos = instr (searchstring, searchchar) 'returns 9.
Mypos = instr (1, searchstring, "W") 'returns 0.

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.