Skip to main content

Past Blast

Featured Products

Windows Mobile Developer Controls
Windows Mobile Developer Controls
Stay in touch using the DEVBUSS RSS feeds.
 

News

Windows Mobile Developer Controls
Windows Mobile Developer Controls

Dynamic HTML display from your eVB application using XML/XSL

Written by Jason Hawgood  [author's bio]  [read 56261 times]
Edited by Derek

Download the code

Page 1  Page 2  Page 3 

Overview

In this article I will demonstrate a technique for retrieving Extensible Markup Language (XML) data from a SQL Server over the web, and then applying Extensible Stylesheet Language (XSL) to the returned data and outputting HTML directly to your eVB application.

Requirements

  • Optional: XML Support Installed on SQL Server 2000, check out the XML support in Microsoft® SQL Server™ 2000. (NOTE: if you do not have access to SQL Server with XML support installed, I have included pre-generated files for the sample application.)
  • WebBrowserCE, a web browser control for eVB, download a trial version.
  • MSXML version 2.0 (msxml.dll).

The Application

With the next generation of pocket applications XML will be the primary transport mechanism for data from information sources like a databases or web services. That said, how can developers robustly output XML data to Pocket PC users. One approach I will explore in this article is using HTML from an eVB application using the WebBrowserCE control from IntelProg.com.

Setting Up the Application

When using XML from eVB you will need to set references to the MSXML.dll and the WebBrowserCE 1.0 Type library. For detailed instruction on registering the WebBrowserCE library for your device, see the ReadMe.txt file included with the control. Additionally, copy the Employees.xml, Employees.xsl, EmployeesDetail.xsl and NWINDTRADERS.gif files to the “\windows\start menu\” directory in emulation or your device.


Reference Microsoft XML, version 2.0 and WebBrowserCE 1.0 Type Library

Requesting XML Data

Now, for the fun stuff. Here is a snippet of the Employees.xml file that we will transform with XSL.

If you do not have SQL Server with SQLXML support you can use the static XML file include with the source code. Be sure to make the necessary changes to the BuildDirectory subroutine described in the code comments. SQL Server XML support is a very powerful technology that allows extremely fast retrieval of XML directly from a SQL Server via HTTP protocol. For more information, see Microsoft® SQL Server™ 2000.

To begin we need to define several global level variables to handle the XML and XSL document objects and the WebBrowserCE control.

'Global XML object
Public gXMLDoc As MSXML.DOMDocument

'Global XSL object
Public gXSLDoc As MSXML.DOMDocument

'WebBrowser Control
Public objHtml As WEBBROWSERCELib.HTMLViewerCtl

'HTML to render
Public gsHTML As String
'XMLSQL Service URL
Public gURL As String

In the Form_Load event handler of the main form, add the following code.

Set objHtml = CreateObjectWithEvents("WebBrowserCE.HTMLViewerCtl", "HTMLView_")

'Full version requires license'
objHtml.LicenseKey = ""
objHtml.create (frmContainer.hWnd)

'Define Initial Position of HTML control
objHtml.Left = 0
objHtml.Top = 49
objHtml.Width = 240
objHtml.Height = 195

'Define Service URL, NOTE: you can use a template xml file instead of submitting query directly
gURL= _ "http://YOURSERVER/NWINDS?SQL=Select+*+from+Employees+order+
by+LastName+for+xml+raw&root=EmployeesList"

Call BuildDirectory

The proceeding code will instantiate the WebBrowserCE control, and assign the start up location and size. Now we can call the BuildDirectory subroutine to display the text. This subroutine wraps the call the SQL server and displays the HTML output.

We can then load the XML directly into our global XMLDOM object with the loadXML method, which in turn calls the GetXMLByHTTP function.

Set gXMLDoc = CreateObject("Microsoft.XMLDOM")gXMLDoc.loadXML GetXMLByHTTP(gURL)

The GetXMLByHTTP function makes a HTTP request to SQL Server for our XML data using the XMLHTTP object. Notice we are returning our XML data as a string variable that has been stripped of encoding and reference entities replaced.

Next Page