Combination of XML and HTML (below)

xiaoxiao2021-03-06  89

XML nested treatment

In general, the result set we have obtained from the database is very large, so when returning from the server to the client, the data is divided into several pages separately. At this point, use the DataPagesize property in the Table element to specify the number of items containing the record set entry.

E.g:

Obviously, if the XML data format is symmetrical, the effect will be fine if it is mapped to the ADO record set or bind to the form element. In practical applications, XML data is a non-symmetrical example. For example, the authors of a book may not only, this will have a certain amount of trouble when mapping and binding. The solution to the problem is to use nested. Each row is still corresponding to a main element, and each column also corresponds to a child element. For repeating elements, use nested forms. We assume that in Books.xml, the first book author is Dean Straight, the second book of the second book is Charlotte Cooper, Shelley Burke and Regina Murphy. At this point, the binding process is as follows:

● Create a Table element and assign the data island ID to the DataFld property;

● For separate XML elements, such as , create TD elements, and set the corresponding DataFld property;

● For repeating elements, nested a table in TD elements;

● Display the author information in the form of a single row.

Note that the DataFld property here must be set to "$ TEXT",

The content that guarantees the nested element is all displayed in the specified element.

The complete HTML code is as follows:

Title

ISBN

Author

In fact, the best use of DSO effect is for structural symmetrical data, and the more effective way to handle non-symmetrical data is to use the DOM technology that we will introduce later.

DSO technology application

1. Access element properties

The properties of the DSO access element are simple, and the properties can be processed directly by sub-elements.

E.g:

......

Thus, when bound to the HTML table, you can process the child element directly:

If the attribute name is the same as the sub-element name, add "!" To distinguish before the element name. 2. Traversal record

DSO is a major advantage to handle XML data island as an ADO record set is that the data sources can be accessed using the various methods provided by ADO, especially when binding the data island to HTML elements such as span, div, and input. Usually these elements show the first record of the record set. To traverse the record set, you can use ADO methods: Move, MoveFirst, Movese, 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 record one by one.

E.g:

SUB btnnext_onclick ()

XMLDSO.Recordset.movenext

End Sub

3. Combined with Script language

Some users are used to writing Script language, using DSO technology, can also be combined with various Script.

For example (as an example of VB Script), the code is as follows:

DIM RSBOOKS

Set rsbooks = xmldso.recordset

Visit field (child elements):

DIM Stitle

Stitle = RSBooks ("Title")

You can pass the obtained value to the HTML element using the InnerText and InnerHTML properties. For example, there is a DIV element named Divtitle, and the value code is as follows:

Divtitle.innertext = Stitle

Many DSO events can also be handled using scripts, and some of the following tables are listed:

The method of processing various events in the script is to specify the XML data island ID in the