Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of Desktop Application based on XML

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces the XML-based desktop application sample analysis, has a certain reference value, interested friends can refer to, I hope you read this article after a lot of gains, the following let Xiaobian take you to understand.

As mentioned earlier, XSL allows us to present the same data in different data forms to end users, one XSL file describes how the data is displayed, and you can connect many XSLs to the same xml document to provide different HTML-based representations, so that, in fact, we can build XML-based desktop applications. A graphical representation based on the Windows architecture looks like this:

There are two main advantages to this approach. First, you can manipulate data in platform-and language-independent ways, and second, you can implement different views of the same data without programming.

In fact, you need a tool that can convert raw data into XML format and then present it in HTML format. In fact, in IE 5.0, you can implement different views of your data through its support for XSL. You can use the built-in XSL processor to produce output from XML streams. Developers can write different XSL scripts and process them with IE's built-in XSL processor. On the other hand, we can convert the recordset to XML format through the inherent functionality of ADO components. The example code is as follows:

If Dir(XML_FILE) = "" Then rs.Save XML_FILE, adPersistXML End If where the constant adPersistXML means using an XML schema to save the contents of the recordset Let's take a closer look at the Save method of the object, which is defined as follows: Save([FileName As String], [PersistFormat As PersistFormatEnum = adPersistADTG])

Each parameter is optional, but the first time you save the recordset to disk, you must specify the name of the file. If there is a valid filter when the method is executed, only data that passes the filter can be saved. When you call the Close method of the object to close the object, the file is automatically closed. After has been saved to disk, you can read it using the Open method, as follows:

rs.open "c:\myrs.xml"

Then let's look at the presentation of XML data. IE5 support for XSL is based on the most recent draft W3C standard. Here we discuss using VB to build an application that accesses data from a data source through the ADO interface. The resulting recordset can be presented in different formats. By writing an XSL document, you can add different views at will.

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

Set rs = New ADODB.Recordset rs.CursorLocation = adUseClient queryString = "select * from Employees" rs.Open queryString, "NorthWind" 'NorthWind is Microsoft's sample database that is easy to find in 'access or SQL SERVER rs.ActiveConnection = Nothing Set DataGrid1.DataSource = rs

In many cases, one view of this is not enough, and you need to exercise strict control over each field. Records in an entire table may be represented as both tables and trees, and providing multiple views makes users feel more comfortable. XML combined with XSL is a good solution to this problem, and you can take full advantage of the Web Browser control in IE5 to browse directly.

The ADO component itself does not generate any XSL documents for the XML documents it generates. This alone does not mean that you cannot write a generic XSL document yourself to change the way data is displayed. For example, in order to automatically display an XML document containing ADO recordsets as a table, you need to add the following code to the XML document header:

The simple.xsl file must be placed in the same directory as the XML document, and it contains two nested loops, the first loop enumerates all the attributes of the element, and the names of these attributes are displayed as headers on the first line, and the second loop outputs all the records in the recordset.

The code for the simple.xsl file looks like this:

RowsetSchema

Note here the syntax for enumerating all attributes of a given node. In fact, we need to get all attributes of any element. The string @* indicates all attributes.(The name of an attribute always needs to be preceded by @. To use this value, the node must set the attribute that matches it, denoted by @*.)

By using the Web Browser control as your engine for browsing data, you can use XML and XSL to separate content from the presentation layer. In this model, XSL acts as a markup language (not a programming language) describing how to display XML data, and in order 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 to MFC document/view model.

Finally, what is the difference between XSL and CSS? The key difference is that XSL applies to the entire XML document, whereas CSS affects only the presentation of HTML tags. XSL is a markup language for processing files, and CSS is a collection of attributes used to represent attributes of an element in a markup language. Furthermore, XSL can use CSS when producing HTML output from XML data streams, which are two different technologies from the current perspective.

Thank you for reading this article carefully. I hope that the article "Sample Analysis of XML-based Desktop Applications" shared by Xiaobian will be helpful to everyone. At the same time, I hope that everyone will support it a lot and pay attention to the industry information channel. More relevant knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report