Home Backend Development XML/RSS Tutorial Detailed introduction to graphic code of XML-based desktop applications

Detailed introduction to graphic code of XML-based desktop applications

Mar 06, 2017 pm 04:48 PM

As mentioned earlier, through XSL, we can submit the same data to end customers in different data forms. An XSL file describes the display method of the data. You can connect many XSLs to the same xml document to provide Different HTML-based representations, so in fact, we can build XML-based desktop applications. A graphical representation based on the Windows architecture looks like this:

Detailed introduction to graphic code of XML-based desktop applications

There are two main advantages to using this approach. First, you can operate in a platform- and language-independent manner. Data, secondly, you can implement different view representations of the same data without programming.

Actually, you need a tool that can convert the original data into XML format, and then express it in HTML format. In fact, in IE5.0, you can achieve different views of data through its support for XSL. You can use the built-in XSL processor to produce output from an XML stream. Developers can write different XSL scripts and then process them using IE's built-in XSL processor. On the other hand, we can convert the recordset into XML format through the inherent functions of the ADO component. The sample code is as follows:

 If Dir(XML_FILE) = "" Then
    rs.Save XML_FILE, adPersistXML
  End If

  这里常量adPersistXML表示使用一个XML纲要来保存记录集的内容

  我们再仔细看一下Recordset对象的Save方法,其定义如下:

   Save([FileName As String], [PersistFormat As PersistFormatEnum = adPersistADTG])
Copy after login

Each parameter is optional, but when you first convert the recordset When saving to disk, you must specify a file name. If there is a valid filter when this method is executed, only data that passes the filter can be saved. When the Recordset object's method Close is called to close the Recordset object, the file is automatically closed. After the Recordset is saved to the disk, you can use the Open method to read it. The specific code is as follows:

   rs.open "c:\myrs.xml"
Copy after login

Then we analyze the issue about the display of XML data. IE5's support for XSL is based on the recent W3C draft standards established. Here we discuss using VB to build an application that accesses data in the data source through the ADO interface. The resulting record set can be displayed in different formats. By writing XSL documents, 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 the data. The specific code is as follows:

 Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient

   queryString = "select * from Employees"
   rs.Open queryString, "NorthWind" 'NorthWind是微软的示例数据库,很容易在
    'access或者是SQL SERVER中找到
   rs.ActiveConnection = Nothing 
   Set DataGrid1.DataSource = rs
Copy after login

In many cases, a view of this is not enough, you need strict control over each field. The records in the entire table may be represented in the form of both tables and trees. Providing multiple views will make users feel more comfortable. The combination of XML and XSL is a good solution to this problem. You can make full use of the functionality of the WebBrowser control in IE5 for direct browsing.
The ADO component itself does not generate any XSL documents from the XML documents it generates. This doesn't mean that you can't write a generic XSL document yourself to change the way the data is displayed. For example, in order to automatically display an XML document containing an ADO record set in table form, you need to add the following code to the head of the XML document:

  <?xml-stylesheet type="text/xsl" href="simple.xsl"?>
Copy after login

This simple.xsl file must be placed with the XML document In the same directory, it contains two nested loops. The first loop enumerates all attributes of the element. The names of these attributes are displayed as titles on the first line. The second loop is used to output all records in the recordset. .

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

<?xml version="1.0"?>
  <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl" 
   xmlns:html="http://www.w3.org/TR/REC-html40"
   result-ns=""
   language="JScript">
  <xsl:template match="/">
  <html>
  <head>
  <title>RowsetSchema</title>
  <style>
   .stdText 
   {
    font-Family:verdana;
    font-Size: 9px;
   }
  </style>
  </head>
  <body>
   <table width="100%" border="1">
   <xsl:for-each select="xml/s:Schema/s:ElementType/s:attribute">
    <th class="stdText"><xsl:value-of select="@type" /></th>
    </xsl:for-each>
    <xsl:for-each select="xml/rs:data/z:row">
    <tr>
     <xsl:for-each select="@*">
     <td class="stdText" valign="top"><xsl:value-of match="@*"/></td>
     </xsl:for-each>
    </tr>
    </xsl:for-each>
   </table>
  </body>
  </html>
  </xsl:template>
  </xsl:stylesheet>
Copy after login

What needs to be noted here is the syntax for listing all attributes of a given node. In fact, we need to get any All attributes of the element, the string @* represents all attributes (the name of an attribute always needs to be preceded by @. In order to use this value, the node must set the attribute that matches it, use @*Presentation.

By using the WebBrowser control as the engine for browsing your data, you can use XML and XSL to separate the content from the presentation layer. In this model, XSL acts as a markup. language (rather than a programming language) to describe how to display XML data. 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 combined with the document under MFC. / View model analogy

Finally, we need to talk about the difference between XSL and CSS? The key difference is that XSL is applied to the entire XML document, while CSS only generates the display form of HTML tags. Impact. XSL is a markup language for processing documents, and CSS is a set of attributes used to represent the attributes of an element in the markup language. Moreover, XSL can use CSS to generate HTML output from the XML data stream. From a perspective, they are two different technologies.

The above is the detailed introduction of the graphic code of XML-based desktop applications. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Can I open an XML file using PowerPoint? Can I open an XML file using PowerPoint? Feb 19, 2024 pm 09:06 PM

Can XML files be opened with PPT? XML, Extensible Markup Language (Extensible Markup Language), is a universal markup language that is widely used in data exchange and data storage. Compared with HTML, XML is more flexible and can define its own tags and data structures, making the storage and exchange of data more convenient and unified. PPT, or PowerPoint, is a software developed by Microsoft for creating presentations. It provides a comprehensive way of

Using Python to merge and deduplicate XML data Using Python to merge and deduplicate XML data Aug 07, 2023 am 11:33 AM

Using Python to merge and deduplicate XML data XML (eXtensibleMarkupLanguage) is a markup language used to store and transmit data. When processing XML data, sometimes we need to merge multiple XML files into one, or remove duplicate data. This article will introduce how to use Python to implement XML data merging and deduplication, and give corresponding code examples. 1. XML data merging When we have multiple XML files, we need to merge them

Filtering and sorting XML data using Python Filtering and sorting XML data using Python Aug 07, 2023 pm 04:17 PM

Implementing filtering and sorting of XML data using Python Introduction: XML is a commonly used data exchange format that stores data in the form of tags and attributes. When processing XML data, we often need to filter and sort the data. Python provides many useful tools and libraries to process XML data. This article will introduce how to use Python to filter and sort XML data. Reading the XML file Before we begin, we need to read the XML file. Python has many XML processing libraries,

Convert XML data to CSV format in Python Convert XML data to CSV format in Python Aug 11, 2023 pm 07:41 PM

Convert XML data in Python to CSV format XML (ExtensibleMarkupLanguage) is an extensible markup language commonly used for data storage and transmission. CSV (CommaSeparatedValues) is a comma-delimited text file format commonly used for data import and export. When processing data, sometimes it is necessary to convert XML data to CSV format for easy analysis and processing. Python is a powerful

Import XML data into database using PHP Import XML data into database using PHP Aug 07, 2023 am 09:58 AM

Importing XML data into the database using PHP Introduction: During development, we often need to import external data into the database for further processing and analysis. As a commonly used data exchange format, XML is often used to store and transmit structured data. This article will introduce how to use PHP to import XML data into a database. Step 1: Parse the XML file First, we need to parse the XML file and extract the required data. PHP provides several ways to parse XML, the most commonly used of which is using Simple

Develop powerful desktop applications with Golang Develop powerful desktop applications with Golang Mar 19, 2024 pm 05:45 PM

Use Golang to develop powerful desktop applications. With the continuous development of the Internet, people have become inseparable from various types of desktop applications. For developers, it is crucial to use efficient programming languages ​​to develop powerful desktop applications. This article will introduce how to use Golang (Go language) to develop powerful desktop applications and provide some specific code examples. Golang is an open source programming language developed by Google. It has the characteristics of simplicity, efficiency, strong concurrency, etc., and is very suitable for

Python implements conversion between XML and JSON Python implements conversion between XML and JSON Aug 07, 2023 pm 07:10 PM

Python implements conversion between XML and JSON Introduction: In the daily development process, we often need to convert data between different formats. XML and JSON are common data exchange formats. In Python, we can use various libraries to convert between XML and JSON. This article will introduce several commonly used methods, with code examples. 1. To convert XML to JSON in Python, we can use the xml.etree.ElementTree module

Handling errors and exceptions in XML using Python Handling errors and exceptions in XML using Python Aug 08, 2023 pm 12:25 PM

Handling Errors and Exceptions in XML Using Python XML is a commonly used data format used to store and represent structured data. When we use Python to process XML, sometimes we may encounter some errors and exceptions. In this article, I will introduce how to use Python to handle errors and exceptions in XML, and provide some sample code for reference. Use try-except statement to catch XML parsing errors When we use Python to parse XML, sometimes we may encounter some

See all articles