A few tweaks...
Option Explicit
Public Sub XMLTest()
Dim strNewFormName As String
strNewFormName = Me.Request.Value
Dim xmldoc As MSXML2.DOMDocument
Set xmldoc = New MSXML2.DOMDocument
Call xmldoc.Load("C:\Users\Phil Millington-Hore\Documents\Programming\Visual Basic\ADL\Golds\DelOptiChaR\XML\2002_01.xml") 'load an existing Infopath form linked to underlying Access DB
'xmldoc. need syntax to manipulate xml document root element data to match currently open Access form fields
Call XmlReader(xmldoc.DocumentElement)
If Len(Dir("C:\PhilAI\test.xml")) > 0 Then Call Kill("C:\PhilAI\test.xml")
Call xmldoc.Save("C:\PhilAI\test.xml") 'save modified file to known location
Set xmldoc = Nothing 'clear xmldoc parameters
End Sub
Public Sub XmlReader(ByRef domRoot As Object)
Dim currentNode As IXMLDOMNode
Dim rootNode As IXMLDOMNode
On Error GoTo ERR_HANDLER
If TypeOf domRoot Is IXMLDOMNode Then
Set rootNode = domRoot
Else
GoTo PROCEDURE_EXIT
End If
For Each currentNode In rootNode.ChildNodes
Debug.Print currentNode.nodeName
If currentNode.ChildNodes.Length > 0 Then
Call XmlReader(currentNode)
End If
Next
PROCEDURE_EXIT:
Set currentNode = Nothing
Set rootNode = Nothing
Exit Sub
ERR_HANDLER:
Debug.Print "Error #" & Err.Number & ": " & Err.Description
Resume PROCEDURE_EXIT
End Sub
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51:





by: PhilAIPosted on 2009-08-21 at 22:31:19ID: 25157486
Here's a function to help you loop through the nodes within an XML.
You can update the text in a node by simply use the text property of a IXMLDOMNode object.
Let me know if you require further assistance.
Select allOpen in new window