Results 1 to 10 of 10

Thread: [RESOLVED] i always get an error trying to read a xml file why?

  1. #1

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Resolved [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

  2. #2
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,906

    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.

  3. #3

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Re: i always get an error trying to read a xml file why?

    Quote Originally Posted by Arnoutdv View Post
    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

  4. #4
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,906

    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

  5. #5

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Re: i always get an error trying to read a xml file why?

    Quote Originally Posted by Arnoutdv View Post
    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?

  6. #6
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,906

    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

  7. #7

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Re: i always get an error trying to read a xml file why?

    Quote Originally Posted by Arnoutdv View Post
    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

  8. #8

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    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?

  9. #9
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,906

    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?

  10. #10

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Re: [RESOLVED] i always get an error trying to read a xml file why?

    Quote Originally Posted by Arnoutdv View Post
    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
  •  



Click Here to Expand Forum to Full Width