-
Jan 17th, 2017, 12:45 AM
#1
Thread Starter
Enjoy the moment
[RESOLVED] i always get an error trying to read a xml file why?
hey
i found a code here that suppose to read some data from a xml file
but no matter what i do i get a error why?
the files are there
Code:
Dim xmlDoc As DOMDocument
Dim objNodeList As IXMLDOMNodeList
Dim objProductNode As IXMLDOMNode
Dim objQuantityNode As IXMLDOMNode
Dim objNode As IXMLDOMNode
Dim XMLurl As String
Dim strRet As String
Set xmlDoc = New DOMDocument
XMLurl = "C:/GoogleSync/*.out"
xmlDoc.async = False
If xmlDoc.Load(XMLurl) = False Then
MsgBox ("XML LOAD ERROR")
Else
Set objNodeList = xmlDoc.selectNodes("//Calender")
For Each objNode In objNodeList
Set objProductNode = objNode.selectSingleNode("EventID")
strRet = "EventID = " & objProductNode.Text
MsgBox strRet
Next objNode
End If
any help will be appreciated
salsa
-
Jan 17th, 2017, 01:56 AM
#2
Re: i always get an error trying to read a xml file why?
Because you don't specify a filename, you pass a partial filename with a wildcard in it.
-
Jan 17th, 2017, 02:48 AM
#3
Thread Starter
Enjoy the moment
Re: i always get an error trying to read a xml file why?
Originally Posted by Arnoutdv
Because you don't specify a filename, you pass a partial filename with a wildcard in it.
i did
this is the filename
GoogleSync
i want to collect all the xml that ends with .out
-
Jan 17th, 2017, 02:54 AM
#4
Re: i always get an error trying to read a xml file why?
First collect all files using the Dir() function and then feed them one by one to the XML read routine
-
Jan 17th, 2017, 03:11 AM
#5
Thread Starter
Enjoy the moment
Re: i always get an error trying to read a xml file why?
Originally Posted by Arnoutdv
First collect all files using the Dir() function and then feed them one by one to the XML read routine
can you show me how?
-
Jan 17th, 2017, 03:27 AM
#6
Re: i always get an error trying to read a xml file why?
You live an copy and paste dont' you? :-P
Untested, typed in the Quick Reply window
Code:
Private Sub Form_Click()
Dim sReturn As String
Dim cFiles As Collection, lFile As Long, sFile As String
Set cFiles = CollectFiles("C:\GoogleSync","*.out")
For lFile = 1 To cFiles.Count
sFile = cFiles(lFile)
sReturn = sReturn & vbCrLf & YourXMLRoutine (sFile)
Next lFile
End Sub
Private Function YourXMLRoutine(XMLurl As String) As String
Dim xmlDoc As DOMDocument
Dim objNodeList As IXMLDOMNodeList
Dim objProductNode As IXMLDOMNode
Dim objQuantityNode As IXMLDOMNode
Dim objNode As IXMLDOMNode
Dim strRet As String
Set xmlDoc = New DOMDocument
xmlDoc.async = False
If xmlDoc.Load(XMLurl) = False Then
MsgBox ("XML LOAD ERROR")
Else
Set objNodeList = xmlDoc.selectNodes("//Calender")
For Each objNode In objNodeList
Set objProductNode = objNode.selectSingleNode("EventID")
YourXMLRoutine = YourXMLRoutine & vbCrLf & "EventID = " & objProductNode.Text
Next objNode
End If
End Function
Private Function CollectFiles(sFolder As String, sFilter As String) As Collection
Dim sFile As String
Set CollectFiles = New Collection
sFile = Dir$(sFolder & "\" & sFilter)
Do While Len(sFile) > 0
CollectFiles.Add sFolder & "\" & sFile
sFile = Dir$
Loop
End Function
-
Jan 17th, 2017, 03:38 AM
#7
Thread Starter
Enjoy the moment
Re: i always get an error trying to read a xml file why?
Originally Posted by Arnoutdv
You live an copy and paste dont' you? :-P
Untested, typed in the Quick Reply window
Code:
Private Sub Form_Click()
Dim sReturn As String
Dim cFiles As Collection, lFile As Long, sFile As String
Set cFiles = CollectFiles("C:\GoogleSync","*.out")
For lFile = 1 To cFiles.Count
sFile = cFiles(lFile)
sReturn = sReturn & vbCrLf & YourXMLRoutine (sFile)
Next lFile
End Sub
Private Function YourXMLRoutine(XMLurl As String) As String
Dim xmlDoc As DOMDocument
Dim objNodeList As IXMLDOMNodeList
Dim objProductNode As IXMLDOMNode
Dim objQuantityNode As IXMLDOMNode
Dim objNode As IXMLDOMNode
Dim strRet As String
Set xmlDoc = New DOMDocument
xmlDoc.async = False
If xmlDoc.Load(XMLurl) = False Then
MsgBox ("XML LOAD ERROR")
Else
Set objNodeList = xmlDoc.selectNodes("//Calender")
For Each objNode In objNodeList
Set objProductNode = objNode.selectSingleNode("EventID")
YourXMLRoutine = YourXMLRoutine & vbCrLf & "EventID = " & objProductNode.Text
Next objNode
End If
End Function
Private Function CollectFiles(sFolder As String, sFilter As String) As Collection
Dim sFile As String
Set CollectFiles = New Collection
sFile = Dir$(sFolder & "\" & sFilter)
Do While Len(sFile) > 0
CollectFiles.Add sFolder & "\" & sFile
sFile = Dir$
Loop
End Function
WOW Genius!!!!!!!!!
tnk you very much
-
Jan 17th, 2017, 05:57 AM
#8
Thread Starter
Enjoy the moment
Re: [RESOLVED] i always get an error trying to read a xml file why?
tell me sir
if i want to read another thing from xml how do i do that?
this only return 1 thing the eventid
Code:
YourXMLRoutine = YourXMLRoutine & vbCrLf & "EventID = " & objProductNode.Text
i need to read another line called date
can you show me please how its done?
-
Jan 17th, 2017, 07:52 AM
#9
Re: [RESOLVED] i always get an error trying to read a xml file why?
I never work with XML libraries, but have you tried to replace "EventID" by "Date"?
Can you paste the content of a XML file?
-
Jan 17th, 2017, 09:23 AM
#10
Thread Starter
Enjoy the moment
Re: [RESOLVED] i always get an error trying to read a xml file why?
Originally Posted by Arnoutdv
I never work with XML libraries, but have you tried to replace "EventID" by "Date"?
Can you paste the content of a XML file?
well i found a way
Code:
Set ObjNodeStart = objNode.selectSingleNode("Start")
YourXMLRoutine = YourXMLRoutine & vbCrLf & "Start = " & ObjNodeStart.Text
ObjStart = ObjNodeStart.Text
thank you amigo
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|