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 the XML data into the grid control is pretty straightforward. The first step is to declare some additional objects for holding the XML nodes that are needed to display the data.

Dim xmlNodeList As IXMLDOMNodeList
Dim xmlNode As IXMLDOMNode
Dim xmlChildNode As IXMLDOMNode

The next step is to add column headings to the grid. This can be done by selecting the child nodes of the first employee node (i.e., the employeeid, firstname, lastname, and title nodes) and then using the baseName property each node as the column name.

Dim i As Integer
'Retrieve the list of child nodes from the first employee node
'(i.e., employeeid,firstname,lastname,title)
Set xmlNodeList = xmlDoc.selectSingleNode("//employee").childNodes

' Hide the grid, add the columns and the first row
gridEmployees.Visible = False
gridEmployees.Cols = xmlNodeList.length
gridEmployees.Rows = 1

' Reset focus to the first row
gridEmployees.Row = 0

'Use the baseName property of each node
'to write the column headings
i = 0
For Each xmlNode In xmlNodeList
gridEmployees.Col = i
gridEmployees.Text = xmlNode.baseName
gridEmployees.CellBackColor = &HC0C0C0
i = i + 1
Next

Finally, select the whole collection of "employee" nodes and iterate through each child node to display the value for each column using the Text property of the node.

' Retrieve the list of employee nodes
Set xmlNodeList = xmlDoc.selectNodes("//employee")

' Add a new row for each employee node
For Each xmlNode In xmlNodeList
gridEmployees.Rows = gridEmployees.Rows + 1
gridEmployees.Row = gridEmployees.Rows - 1

' Use the Text property of each node
' to write the column values
i = 0
For Each xmlChildNode In xmlNode.childNodes
gridEmployees.Col = i
gridEmployees.Text = xmlChildNode.Text
i = i + 1
Next
Next

' Reset the focus to the top-left cell in the grid
' and make the grid visible
gridEmployees.Col = 0
gridEmployees.Row = 0
gridEmployees.Visible = True

Conclusion

Despite the lack of documentation, using XML in eVB is actually quite simple. If you've used XML from VB 6, then I'm sure you'll have no trouble using it from eVB. If not, this example should give you the jumpstart that you need to begin integrating XML into your eVB applications.

MSDN Topics

XML Reference
XML Tutorial
XML for Windows CE
Differences Between Microsoft XML 2.0 and Microsoft XML 2.5
Microsoft XML 2.0 Features That WINCE Does Not Support
XML for Windows CE

Previous Page