Resolving user interface problems with XML data Islands-2

Source: Internet
Author: User
Tags object contains interface query return xml parser xsl client
xml| Resolution | data | Problems move the process to the client

When the Web server returns to the Web page, all further actions are processed on the client. I used to think that if you send a large data assembly to the client, the program slows down. But then I found that sending all the data at once was much faster than exchanging data back and forth between the client and the server. The only pause that can be noticed is a brief initialization pause when the IE5 XML parser reads the data.

The HTML file itself contains 4 elements: a select list (the master list) that holds the state name data, the XML data, the div-tag placeholder for a subordinate list, and two scripts. The second script executes (Listing 2) When the option of the state name selection list changes.

You want to be able to get the appropriate store list from the data island each time a user chooses a state. So you need a script to handle the onchange event for the state list of choices:

  

In this script, the value of the state name select list is again:
Dim statecode

Statecode=document.all.state.value

The list of stores in the selected state is then restarted. You can get this list in two ways. The first option is to get a reference to the Recordset property of the <XML> tag character:

Dim R

Set R = Xmldata.recordset

The recordset obtained by this method is a standard ADO Recordset object, and the field names correspond to the markers. This method works well only if you have a simple XML data file with the same field for each record.

The second method is more powerful and universal. IE5 treats XML data islands like other HTML elements. In order to access the XML data on the client, you simply refer to the element by ID. IE5 will return the root element of the XML tree (document Element):

Set xml = document.all ("XMLData")

You use this document element to perform extensible Stylesheet Language (XSL) query statements. Using XSL query statements, you can get a list of nodes at a given level, a list of nodes that contain the specified attributes, or any combination of both. For example, the following query statement returns all store nodes that meet the user's chosen state:

Dim nodes

Set nodes = Xml.selectnodes ("locations/state[@code = '" & Statecode & "']/store")

The XSL search string looks much like a file path, and it has values for the corresponding levels of the XML tree. Separate each level with "/". Searches for a specified number of nodes in the [] of the associated node with a match of "node = number", and "@" before the property name to search for the node that contains the specified attribute. Running the SelectNodes method returns a Ixmldomnodes collection object. Finally, the subordinate list is displayed. Easiest way: To change the label of a subordinate list based on the list of nodes returned by the XSL query statement
The value of the character:

Set alist = document.all ("Cities")

AList.options.length = 0

i = 0

For all N in nodes

Anid = N.selectsinglenode ("id"). Text

Acity = N.selectsinglenode _ ("City"). Text

AList.options.length = _alist.options.length + 1

Alist.options (i). id = Anid

Alist.options (i). Value = acity

Alist.options (i) innertext = acity

i = i + 1

Next

Now you know how to use an XML data island to solve a dependent list problem. Note: This technique is not suitable for large-scale data-such as those of thousands of records-but in that case, it is mostly a question of how to display, not a technical one. If you find that a query statement might return a large set of records that are not appropriate, you can limit the number of records to be returned (for example, by providing a "more record" button for the user) and modify the user interface so that users can click on the next level of content, thereby limiting the number of entries that the user must select.



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.