| | |
Read/Edit specific .xml nodes in vb6
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jun 2008
Posts: 4
Reputation:
Solved Threads: 0
So far i have managed to butcher some code i found around 12mth ago to allow me to read the relevant node but i'm struggling to find out how to edit this node value and save the xml file. I cant find where i got this from or anything similar. I expect a lot of the code can be stripped out:
Option Explicit
Dim strXMLFilePath As String
Dim objXMLDOM As New MSXML2.DOMDocument26
Dim objNodes As IXMLDOMNodeList
Dim objBookNode As IXMLDOMNode
Dim objFSO As Object
Dim ObjFile As Variant
Dim ObjFolder As Variant
Dim Nodevalue
Dim Nodevalue1
Dim Appexe1
Private Sub Command1_Click()
Call ReadXMLFiles
End Sub
Sub ReadXMLFiles()
On Error GoTo ErrorHandler ' Enable error-handling routine.
Set objFSO = CreateObject("Scripting.FileSystemObject")
strXMLFilePath = App.Path
If objFSO.FolderExists(strXMLFilePath) Then
Set ObjFolder = objFSO.GetFolder(strXMLFilePath)
For Each ObjFile In ObjFolder.Files
If InStr(ObjFile.Type, "XML") > 0 Then
Call LoadXMLFiles(strXMLFilePath, "system.xml")
Call ReadFile
'FileCopy SourceFile, TargetFile '// If you want to copy from some Different location
'Kill (strXMLFilePath & ObjFile.Name)'// You Can Kill the File if you want after reading
End If
Next
End If
Set ObjFolder = Nothing
Set ObjFile = Nothing
Set objFSO = Nothing
Exit Sub ' Exit to avoid handler.
ErrorHandler: ' Error-handling routine.
Set ObjFolder = Nothing
Set ObjFile = Nothing
Set objFSO = Nothing
End
End Sub
Sub LoadXMLFiles(strXMLFilePath As String, strXMLFileName As String)
On Error GoTo ErrorHandler ' Enable error-handling routine.
objXMLDOM.async = False
objXMLDOM.Load (strXMLFilePath & "\" & strXMLFileName)
Exit Sub ' Exit to avoid handler.
ErrorHandler: ' Error-handling routine.
Set objXMLDOM = Nothing
End
End Sub
Sub ReadFile()
Set objNodes = objXMLDOM.selectNodes("/NewDataSet/System")
For Each objBookNode In objNodes
If objBookNode.selectNodes("WebServiceInternalURL").length <> 0 Then
Appexe1 = objBookNode.selectSingleNode("WebServiceInternalURL").nodeTypedValue
Debug.Print Appexe1
Text1 = (Appexe1)
End If
Next objBookNode
End Sub
Option Explicit
Dim strXMLFilePath As String
Dim objXMLDOM As New MSXML2.DOMDocument26
Dim objNodes As IXMLDOMNodeList
Dim objBookNode As IXMLDOMNode
Dim objFSO As Object
Dim ObjFile As Variant
Dim ObjFolder As Variant
Dim Nodevalue
Dim Nodevalue1
Dim Appexe1
Private Sub Command1_Click()
Call ReadXMLFiles
End Sub
Sub ReadXMLFiles()
On Error GoTo ErrorHandler ' Enable error-handling routine.
Set objFSO = CreateObject("Scripting.FileSystemObject")
strXMLFilePath = App.Path
If objFSO.FolderExists(strXMLFilePath) Then
Set ObjFolder = objFSO.GetFolder(strXMLFilePath)
For Each ObjFile In ObjFolder.Files
If InStr(ObjFile.Type, "XML") > 0 Then
Call LoadXMLFiles(strXMLFilePath, "system.xml")
Call ReadFile
'FileCopy SourceFile, TargetFile '// If you want to copy from some Different location
'Kill (strXMLFilePath & ObjFile.Name)'// You Can Kill the File if you want after reading
End If
Next
End If
Set ObjFolder = Nothing
Set ObjFile = Nothing
Set objFSO = Nothing
Exit Sub ' Exit to avoid handler.
ErrorHandler: ' Error-handling routine.
Set ObjFolder = Nothing
Set ObjFile = Nothing
Set objFSO = Nothing
End
End Sub
Sub LoadXMLFiles(strXMLFilePath As String, strXMLFileName As String)
On Error GoTo ErrorHandler ' Enable error-handling routine.
objXMLDOM.async = False
objXMLDOM.Load (strXMLFilePath & "\" & strXMLFileName)
Exit Sub ' Exit to avoid handler.
ErrorHandler: ' Error-handling routine.
Set objXMLDOM = Nothing
End
End Sub
Sub ReadFile()
Set objNodes = objXMLDOM.selectNodes("/NewDataSet/System")
For Each objBookNode In objNodes
If objBookNode.selectNodes("WebServiceInternalURL").length <> 0 Then
Appexe1 = objBookNode.selectSingleNode("WebServiceInternalURL").nodeTypedValue
Debug.Print Appexe1
Text1 = (Appexe1)
End If
Next objBookNode
End Sub
![]() |
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: text file strings help
- Next Thread: Need help in excel vba for charts
| Thread Tools | Search this Thread |
Tag cloud for Visual Basic 4 / 5 / 6
* 6 429 2007 access activex add age append application basic beginner birth bmp calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver subroutine table tags textbox time timer urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





