The combination of XML and HTML (next)

Source: Internet
Author: User
Tags object query sort xsl client access advantage
Xml nested processing of XML

In general, the result set that we query from the database can be very large, so when returned from the server to the client, the data is divided into several pages for delivery. At this point, you can use the DataPageSize property in the Table element to specify the number of entries per page that contains a recordset.

For example:

Obviously, if the XML data format is symmetric, it will work well whether it is mapped to an ADO recordset or to a TABLE element. In practical applications, there are many examples of XML data asymmetry, such as the author of a book may be more than one, which in mapping and binding time will produce a certain amount of trouble. The way to solve the problem is to use nested nesting. Each row table still corresponds to a main element, and each column corresponds to a child element. For repeating elements, the nested table is used. We assume that in Books.xml, the author of the first book is Dean Straight, and the second book is Charlotte Cooper, Shelley Burke and Regina Murphy. At this point, the binding process is as follows:

Creates a TABLE element and assigns the data island ID to the DATAFLD property;

For a separate XML element, such as , create a TD element and set the corresponding DATAFLD attribute;

For repeating elements, a table is nested inside the TD element;

Displays author information in a single column.

Note that the datafld attribute here must be set to "$TEXT".

To ensure that the contents of the nested element are all displayed in the specified element.

The complete HTML code looks like this:

Title ISBN Author

In fact, the best use of DSO is for structured data, and the more efficient way to handle asymmetric data is to use the DOM technology we'll be introducing later.

the application of DSO technology

1. Accessing the attributes of an element

The use of DSO to access the elements of the property is very simple, you can directly attribute to the child elements to deal with.

For example:

......

In this way, when you bind to an HTML table, you can handle it directly by child elements:

If you encounter the same property name as the child element name, precede the element name with the "!" to differentiate. 2. Traversing a recordset

DSO the XML data island as an ADO recordset processing a great advantage is that the various methods provided by ADO can be used to access the data source, especially when the data island and similar span, div and input HTML elements such as binding time. Typically these elements display the first record of a recordset, and to traverse through the recordset, you can use the methods of ADO: Move, MoveFirst, MoveLast, MoveNext, and MovePrevious. For example, create a button response function, as long as the user clicks on the "Next" button, you can browse the corresponding records.

For example:

Sub Btnnext_onclick ()

Xmldso. Recordset.movenext

End Sub

3. Combined with the script language

Some users are more accustomed to writing script language, using DSO technology can also be combined with a variety of script very well.

For example, in the case of VB script, when accessing the recordset, the code is as follows:

Dim rsbooks

Set rsbooks = Xmldso. RecordSet

To access the value of a field (child element):

Dim Stitle

Stitle = Rsbooks ("title")

You can use the InnerText and innerHTML properties to pass the resulting values to the HTML element. For example, there is a DIV element named Divtitle, and the assignment code looks like this:

Divtitle.innertext = Stitle

There are a number of DSO events that can be handled by using a scripting program, and the following table lists some of these events:

The way to handle various events in a script is to specify the XML data island ID using the for attribute in the

In addition to displaying the record data, the script can quickly query, sort, and edit the recordset. However, while ADO technology provides a way to sort XML data such as SortColumn and sortascending, it is less effective than sorting in XSL, so it is recommended that you take advantage of the XSL technology to achieve this part of the functionality.

The rest of the functionality, such as using a script to do things like add, delete, or modify a recordset, or pagination to display HTML tables, and so on, is not a case in point here, and the usage is similar to the previous operation. Finally, it needs to be explained that all the operation of the DSO object is done in the client, is actually a copy of the server data object, the advantage is to avoid the network to withstand a large number of data communication burden. However, any operation of the client does not affect the data stored on the server, if you want to make changes to the server records, it is necessary to use the server-side data exchange technology, we will be introduced in the future.



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.