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

Getting Started with XML in eVB

Written by Jim Poe  [author's bio]  [read 60151 times]
Edited by Derek

Download the code

Page 1  Page 2  Page 3 

Loading XML into the parser

Once the development environment is configured, creating a DOMDocument object is as simple as declaring a variable and calling CreateObject with the ProgID "Microsoft.XMLDOM".

Dim xmlDoc As DOMDocument
' Create a DOMDocument
Set xmlDoc = CreateObject("Microsoft.XMLDOM")

After the DOMDocument has been instantiated, the next step is to load some XML into the parser. The DOMDocument provides two methods for accomplishing this, load and loadXML. The load method accepts a string containing the path to an XML file and would be the appropriate method for loading XML from a file, but calling the load method causes an "Access Denied" error to thrown using the emulator or on a device.

' This would be the easiest way to load the file into the parser, but...
' Returns an "Access Denied" error in the emulator and on a device
'xmlDoc.Load (App.Path & "\employees.xml")

The only way to workaround this in eVB is to use the loadXML method. This method accepts one parameter which is a string containing actual XML, so you can use the file control to load in the contents of an XML file to a string and then pass the string containing the XML into the parser. The following code illustrates this approach:

'Instead, open the XML file with the file
' control and store the contents in a string
Dim sContactsXML As String
Dim fileXML As File

Set fileXML = CreateObject("FileCtl.File")
fileXML.Open App.Path & "\employees.xml", _
fsModeInput, fsAccessRead, fsLockRead
sContactsXML = fileXML.Input(fileXML.LOF)
fileXML.Close
Set fileXML = Nothing

' Load the XML string into the parser
xmlDoc.loadXML sContactsXML

Navigating the DOM and adding data to a Grid control

I've provided some sample code that loads the contents of an XML file into a Grid control. To run the sample code, you need to copy the XML file onto your device or into the emulator where the program will run. For the emulator on my machine, it's:-

C:\Windows CE Tools\wce300\MS Pocket C\emulation\palm300\windows\start menu\.

The file contains XML data from the Northwind employees table and has the following structure:

Previous Page  Next Page