Page 1
Page 2
Page 3
Page 4
That was the hardest part. Now the easy
one, traversing the XML tree:
Public Sub DisplayXMLDocument()
'set the controls index to zero
initializeControls
lastGroupName = ""
For Each XMLItem In currNode.childnodes
DisplayXMLObject XMLItem
Next
'refresh the frame size and scrollbars size for scrolling
Frame1.Move 0, 0, Me.Width - 260, maxCurrY * 20
VScroll1.Max = Frame1.Height - maxCurrX * 20
VScroll1.LargeChange = VScroll1.Max / 100
VScroll1.SmallChange = VScroll1.Max / 10
End Sub
Now you have traversed a XML tree and
have built the windows controls for it. This will give you
a graphical representation of your XML document as described
in the picture 1. You can play with it and change the vales
in the text box, list box, combo box or radio button just
the way you use any other windows application.
Saving the updated information to
the XML file
Ok, you have changed the necessary
information. How do you save your data into the same file?
It should be easy by now. Just traverse the entire tree
again and you save the necessary XML tag attributes from
the windows controls.
Private Sub saveXMLTree()
Dim k
currentControlsIndex = 0
For k = 0 To (currNode.childnodes.length - 1)
saveXMLNode currNode.childnodes.Item(k)
Next
XMLString = currNode.XML
XMLFileWriter.Open OutputFileName, 2
splitter = Split(XMLString, vbCrLf)
For Each splittedText In splitter
XMLFileWriter.LinePrint Trim(splittedText)
Next
XMLFileWriter.Close
MsgBox "File is saved", vbOKOnly, "Saved"
End Sub
Private Sub saveXMLNode(objXMLItem)
Dim objXMLValue As String
Dim objXMLattribute, objAttributes
Dim XMLElementType As String
Dim numSelected As Long
Dim m As Integer
If objXMLItem.nodeType = XML_Element Then
If LCase(objXMLItem.NodeName) = "input" Then
XMLElementType = LCase(objXMLItem.getAttribute("type"))
If XMLElementType = "text" Then
SendMessage controlsHwnD(currentControlsIndex), EM_SETSEL,
0, GetWindowTextLength(controlsHwnD(currentControlsIndex))
+ 1
SendMessage controlsHwnD(currentControlsIndex), WM_COPY,
0, 0
SendMessage controlsHwnD(currentControlsIndex), WM_PASTE,
0, 0
If Len(Clipboard.GetText) > 0 Then
objXMLItem.setAttribute "value", Clipboard.GetText
Else
objXMLItem.setAttribute "value", ""
End If
Clipboard.Clear
currentControlsIndex = currentControlsIndex + 1
ElseIf XMLElementType = "radio" Then
objXMLValue = SendMessage(controlsHwnD(currentControlsIndex),
BM_GETCHECK, 0, 0) If objXMLValue = "0" Then
objXMLItem.setAttribute "checked", "false"
Else
objXMLItem.setAttribute "checked", "true"
End If
currentControlsIndex = currentControlsIndex + 1
ElseIf XMLElementType = "checkbox" Then
objXMLValue = SendMessage(controlsHwnD(currentControlsIndex),
BM_GETCHECK, 0, 0) If objXMLValue = "0" Then
objXMLItem.setAttribute "value", "no"
Else
objXMLItem.setAttribute "value", "yes"
End If
currentControlsIndex = currentControlsIndex + 1
End If
ElseIf LCase(objXMLItem.NodeName) = "textarea" Then
SendMessage controlsHwnD(currentControlsIndex), EM_SETSEL,
0, GetWindowTextLength(controlsHwnD(currentControlsIndex))
+ 1
SendMessage controlsHwnD(currentControlsIndex), WM_COPY,
0, 0
SendMessage controlsHwnD(currentControlsIndex), WM_PASTE,
0, 0
If Len(Clipboard.GetText) = 0 Then
objXMLItem.Text = ""
Else
objXMLItem.Text = Clipboard.GetText
End If
Clipboard.Clear
currentControlsIndex = currentControlsIndex + 1
ElseIf LCase(objXMLItem.NodeName) = "select" Then
For m = 0 To (objXMLItem.childnodes.length - 1)
numSelected = SendMessage(controlsHwnD(currentControlsIndex),
LB_GETSEL, m, 0) If numSelected = 0 Then
objXMLItem.childnodes.Item(m).setAttribute "selected", "false"
Else
objXMLItem.childnodes.Item(m).setAttribute "selected", "true"
End If
Next
currentControlsIndex = currentControlsIndex + 1
End If
End If
End Sub


Conclusion
So, we have made it. This will look
very complicated at the beginning but after few hours of
debugging, cursing me and some black coffee, you will get
the hang of it. The usage of this kind of application can
be anything, from survey reports to database entry, to what
not. Just for a good understanding, look into the new XHTML
applications and start writing your own browser for WinCE
by adding your own HTTP get/post mechanism. If you need
my help, email me at shakilsiraj@yahoo.com. Good luck.
Read
Part II
Previous Page