Results 1 to 11 of 11
  1. #1
    Fipper_SG is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    23

    How to take text string from xml file and add to table?

    Hi everyone!

    Here's my situation:

    I have a table in Access that list the files from a specific folder:
    - Flink: File's hyperlink
    ...


    - Related_to : Subjects covered into the document


    I also use DTSearch to search the same files for specific keywords and log the results into XML files named by the word I'd like to add in the ''Related to'' column of my Access DB. Here's how the XML created by DTSearch looks like:

    Code:
    <?xml version="1.0" encoding="UTF-8" ?><dtSearchResults>
        <Request>Canada or Quebec or Ontario or British Colombia or Manitoba or Alberta</Request>
        <BooleanConditions></BooleanConditions>
        <FileConditions></FileConditions>
        <TotalFiles>13</TotalFiles>
        <TotalHits>23</TotalHits>
        <SearchFlags>3215620</SearchFlags>
        <SearchDate>2013-03-05 14:08:21Z</SearchDate>
        <dtSearchEngineVersion>8025</dtSearchEngineVersion>
        <Selections>0 1 2 3 4 5 6 7 8 9 10 11 12 </Selections>
        <Item>
            <Filename>F:\00 - Fichiers Personnels\Cours FORCES\Instructeur Premiers Soins\Autre\Transport Improvisé.docx</Filename>
            <Location>F:\00 - Fichiers Personnels\Cours FORCES\Instructeur Premiers Soins\Autre</Location>
            <ShortName>Transport Improvisé.docx</ShortName>
            <Title>Chapitre 18 ***********Sébastien Garneau Temps: 30 minutes ***********Sdt * Tran</Title>
            <DisplayName>Transport Improvisé.docx</DisplayName>
            <IndexRetrievedFrom>C:\Users\Maiko\test</IndexRetrievedFrom>
            <HitsByWord>jambe, 2</HitsByWord>
            <PhraseCount>2</PhraseCount>
            <HitCount>2</HitCount>
            <OriginalHitCount>2</OriginalHitCount>
            <Score>2336</Score>
            <ScorePercent>100</ScorePercent>
            <Hits>127 76 </Hits>
            <Size>16989</Size>
            <TypeID>268</TypeID>
            <ParserID>0</ParserID>
            <Filetype>Word 2007</Filetype>
            <WordCount>395</WordCount>
            <Date>2012-03-20 04:35:55Z</Date>
            <CreateDate>2012-07-31 11:49:11Z</CreateDate>
            <DocId>1648</DocId>
            <IIndex>0</IIndex>
            <IndexedBy>8025</IndexedBy>
            <Ordinal>0</Ordinal>
            <UserFields></UserFields>
        </Item>
        <Item>
            <Filename>F:\00 - Fichiers Personnels\Cours FORCES\Instructeur Premiers Soins\Transport Improvisé.docx</Filename>
            <Location>F:\00 - Fichiers Personnels\Cours FORCES\Instructeur Premiers Soins</Location>
            <ShortName>Transport Improvisé.docx</ShortName>
            <Title>Chapitre 18 ***********Sébastien Garneau Temps: 30 minutes ***********Sdt * Tran</Title>
            <DisplayName>Transport Improvisé.docx</DisplayName>
            <IndexRetrievedFrom>C:\Users\Maiko\test</IndexRetrievedFrom>
            <HitsByWord>jambe, 1</HitsByWord>
            <PhraseCount>1</PhraseCount>
            <HitCount>1</HitCount>
            <OriginalHitCount>1</OriginalHitCount>
            <Score>1204</Score>
            <ScorePercent>51</ScorePercent>
            <Hits>96 </Hits>
            <Size>17032</Size>
            <TypeID>268</TypeID>
            <ParserID>0</ParserID>
            <Filetype>Word 2007</Filetype>
            <WordCount>390</WordCount>
            <Date>2012-09-12 00:31:43Z</Date>
            <CreateDate>2012-09-12 00:18:36Z</CreateDate>
            <DocId>1950</DocId>
            <IIndex>0</IIndex>
            <IndexedBy>8025</IndexedBy>
            <Ordinal>1</Ordinal>
            <UserFields></UserFields>
        </Item>
        <Item>
    </dtSearchResults>
    Note: -This XML is the result for the search ''Canada or Quebec or Ontario or British Colombia or Manitoba or Alberta''.
    -<Filename>THE FILE'S HYPERLINK IS HERE!</Filename>
    - the name of the file is not written anywhere inside... But it is named Canada

    I'm not very good in access VBA...

    How can I tell Access to take the name of the XML Files (or the words up to the first ''or''. This could also be an alternative) and add it to the ''Related to'' column of the records that have their File Hyperlink listed into the XML Files? Also, the ''Related to'' Might have more than one Subject, so the text should be added without removing what was there before....

    Any help will be gladly appreciated!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    Don't understand. Take the name of the XML Files from where?

    The RelatedTo field is a multi-value field or a simple text field?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Fipper_SG is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    23
    from the xml file name. Ex. Canada.xml, i'd like to add canada to the ''related to''columns.

    its a text field. but it could be easily changed if necessary.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    Where will the XML filenames come from? Do you need to cycle through the files in a system folder, read the filenames, extract and save to table? Review http://stackoverflow.com/questions/1...lder-using-vba
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Fipper_SG is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    23
    oh im sory i didn't understand your question right....

    the files would be into the same folder called RelatedTo_Lists. so Dir would effectively be the right way to go!

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    Google: Access VBA get file names

    Here is another http://www.pcreview.co.uk/forums/obt...-t3997550.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    Fipper_SG is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    23
    I'm sorry but I know how to do that. My problem is clearly explained in my first post. I'll keep looking.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    Sorry but I don't entirely understand what you need.

    You know how to read names of files in folder?

    So what is it you need? How to pass the file name (or some part of it) into table?

    Do you need to know how to parse the file name or how to save into table? Saving into table could be simply setting the value of a field/textbox on form:

    Me.textboxname = Me.textboxname & IIf(IsNull(Me.textboxname), "", ", ") & strFileName
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    Fipper_SG is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    23
    Damn it! I almost have it!

    I can't figure out how to do this part: (between the two lines)

    Code:
    'Creates a list of all XML Files in a table (XML_Files) located in the specified directory:
    Call runListXMLFiles
        
    'Refresh:
        Dim f As Form
    
    
        For Each f In Access.Forms
            f.Requery
        Next
     
    Dim DB As DAO.Database
    Set DB = CurrentDb
    
    
    Dim RSTValues As DAO.Recordset
    Set RSTValues = DB.OpenRecordset("Collation", dbOpenDynaset, dbSeeChanges)
    
    
    Dim XMLValues As DAO.Recordset
    Set XMLValues = DB.OpenRecordset("XML_Files", dbOpenDynaset, dbSeeChanges)
    
    
    Dim oDoc As MSXML2.DOMDocument
    Set oDoc = New MSXML2.DOMDocument
    
    
    Dim Path As String
    
    
    
    
    'Select the Path of the First XML File:
    XMLValues.MoveFirst
    
    
    'This loop extract all the filenames that are into the XML File:
    Do
        Path = XMLValues!FPath
                
        'Open Document
        If oDoc.Load(Path) Then
                    
            'Extracting the Filename's Node
            Dim dtSearchResults As MSXML2.IXMLDOMNode
            Dim Item As MSXML2.IXMLDOMNode
            Dim Filename As MSXML2.IXMLDOMNode
                  
            Set dtSearchResults = oDoc.documentElement.childNodes(0)
            
            For Each Item In oDoc.selectNodes("/dtSearchResults/Item")
                Set Filename = Item.selectSingleNode("Filename")
            
                If Not Filename Is Nothing Then           
                    
                    'From the XML Path, extracting the Related to Keyword:
                    Dim Rel_To As String
                    Dim RTStart As String
                    Dim RTinvEnd As String
                    Dim RTEnd As String
                    Dim RTLen As String
                                           
                    RTStart = InStrRev(Path, "\")
                    RTinvEnd = InStrRev(Path, ".")
                    RTEnd = Len(Path) - RTinvEnd
                    RTLen = Len(Path) - RTStart - RTEnd - 1
                    Rel_To = Mid(Path, RTStart + 1, RTLen)
                    
                   '---------------------------------------------------------------------------------
                                              
                        'Search for the first matching record
                        RSTValues.FindFirst ([FPath] = Filename.Text)
                        
                        'Check the result
                        If RSTValues.NoMatch Then
                            MsgBox "Record not found."
                            
                        Else
                    '---------------------------------------------------------------------------------
                            'Adding the Related_to Keyword to the Database:
                            RSTValues.Edit
                            RSTValues("Related_To").Value = RSTValues!Related_To + " " + ";" + " " + Rel_To
                            
                        End If
       
                End If
                Next Item
    
    
        Else
        'Error Handling
        End If
        
        'Go to Next XML Files:
        XMLValues.MoveNext
     
     Loop Until XMLValues.EOF
     
       
    'Refresh:
        For Each f In Access.Forms
            f.Requery
        Next
    Basically, I have a table that is already populated, and one of the column is the files' hyperlink.

    Now, what I want to do, is to Go to the record where the Hyperlink match the one I extracted from the XML file. Any ideas?
    Last edited by Fipper_SG; 03-15-2013 at 05:53 PM. Reason: Typo in the code...

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    Try:

    RSTValues.FindFirst "[FPath] ='" & Filename.Text & "'"

    Recommend & as concatenation operator. The + is left over from ancient Basic.

    RSTValues!Related_To = RSTValues!Related_To & " ; " & Rel_To
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #11
    Fipper_SG is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    23
    Works perfectly Thank you!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Exporting table from access to text file
    By narendrabr in forum Import/Export Data
    Replies: 3
    Last Post: 01-08-2013, 09:59 AM
  2. Replies: 2
    Last Post: 12-27-2012, 09:37 AM
  3. How to update table if linked ot text file
    By cory_jackson in forum Import/Export Data
    Replies: 7
    Last Post: 01-03-2012, 03:19 PM
  4. HELP! how to send data from table to text file
    By daveofgv in forum Import/Export Data
    Replies: 11
    Last Post: 02-14-2011, 01:22 AM
  5. Importing text file into Access Table
    By Anthony in forum Import/Export Data
    Replies: 13
    Last Post: 09-23-2009, 04:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums