XML-based desktop applications

Source: Internet
Author: User
Tags xsl xsl file

As mentioned above, with XSL, we can submit the same data to end users in different forms. An XSL file describes the data display mode, you can connect many XSL with the same XML document to provide different HTML-based representation. In fact, we can build a desktop application based on XML. Program . A graphical representation based on the Windows architecture is as follows:

This method has two main advantages: First, you can operate data in a platform-independent way, and second, you can implement different views of the same data without programming.

In fact, you need a tool to convert the original data into XML format and then express it in HTML format. In ie5.0, you can use it to support XSL to implement different views of data. You can use the built-in XSL processor to generate output from the XML stream. Developers can write different XSL scripts and then process them with the XSL processor built in IE. On the other hand, we can use the internal functions of the ADO component to convert the record set into XML format.CodeAs follows:

If Dir (xml_file) = "then
Rs. Save xml_file, adpersistxml
End if

Here, the constant adpersistxml indicates that an XML outline is used to save the record set content.

Let's take a closer look at the Save method of the recordset object. Its definition is as follows:

Save ([filename as string], [persistformat as persistformatenum = adpersistadtg])

Each parameter is optional, but when you save the record set to the disk for the first time, you must specify the file name. If a valid filter exists when the method is executed, only the filtered data can be saved. When you call the recordset object method close to close the recordset object, the object is also automatically closed. After the recordset is saved to the disk, you can read it using the open method. The specific code is as follows:

Rs. Open "C: \ myrs. xml"

Then let's analyze the XML data display problem. ie5's support for XSL is based on W3C's latest draft standard. Here we will discuss how to use VB to create an application that uses the ADO interface to access data in the data source. The resulting record set can be displayed in different formats. By writing an XSL document, you can add different views at will.

For example, once you extract a result set, you can use the DataGrid Control in VB to conveniently display data. The specific code is as follows:

Set rs = new ADODB. recordset
Rs. cursorlocation = aduseclient

Querystring = "select * from employees"
Rs. Open querystring, "northwind" 'northwind is a Microsoft example database, which is easily stored in
'Access or found in SQL Server
Rs. activeconnection = nothing
Set datagrid1.datasource = rs

In many cases, this view is not enough. You need to strictly control each field. The records in the entire table may be represented in both a table and a tree. Providing multiple views makes users feel more comfortable. The combination of XML and XSL is a good solution to this problem. You can make full use of the webbrowser Control Function in ie5.
The ADO component itself does not generate any XSL documents for the XML documents it generates. This does not mean that you cannot write a general XSL document to change the data display mode. For example, to automatically display an XML document containing an ADO record set in a table, add the following code in the XML document header:

<? XML-stylesheet type = "text/XSL" href = "Simple. XSL"?>

This simple. the XSL file must be placed in the same directory as the XML file. It contains two nested loops. The first loop enumerates all attributes of the element, the names of these attributes are displayed as titles in the first row, and the second loop is used to output all records in the record set.

The code of the simple. XSL file is as follows:


xmlns: html = "http://www.w3.org/TR/REC-html40"
result-NS = "
Language =" jscript ">



rowsetschema


















Note the syntax for listing all the attributes of a given node. In fact, we need to obtain all the attributes of any <Z: Row> element, string @ * indicates all attributes (the name of an attribute must always be prefixed with @. To use this value, the <XSL: value-of> node must set the matching attribute, it is represented.

By using the webbrowser control as your data browsing engine, you can use XML and XSL to separate the content from the presentation layer. In this model, XSL serves as a markup language (insteadProgramming Language) To describe how to display XML data. To add a new view, you only need to add a corresponding XSL document. In fact, this web-based document/view model can be compared with the document/view model under MFC.

Finally, let's talk about the differences between XSL and CSS? The key difference is that XSL is applied throughout the XML document, while CSS only affects the display form of HTML tags. XSL is a markup language for processing files, and CSS is a set of attributes used to represent the attributes of an element in a markup language. Moreover, XSL can use CSS when generating HTML output from XML data streams. From the current perspective, they are two different technologies.

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.