+ Reply to Thread
Results 1 to 10 of 10

Parsing the XML files with VBA

  1. #1
    Registered User
    Join Date
    05-16-2015
    Location
    Nepal
    MS-Off Ver
    2010
    Posts
    12

    Post Parsing the XML files with VBA

    I have a XML file with the information on 20 routes in a city. There are several right turns and left turns made for each trip. I want to count the number of letter"left" and "right" for each trips. How can I do that?

    Capture.PNG

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Parsing the XML files with VBA

    If all you want to do is count the occurrences of "turn_left" and "turn_right", you don't need to parse the xml, basic string functions will do that

  3. #3
    Registered User
    Join Date
    05-16-2015
    Location
    Nepal
    MS-Off Ver
    2010
    Posts
    12

    Re: Parsing the XML files with VBA

    Yes, I wanted to count the occurrences of "turn_left" and "turn_right" for each <Route Name>, as I have around thousand trips in one XML file. Can you provide some hint on using string functions?

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Re: Parsing the XML files with VBA

    Hi !

    Use Split function …

    PHP Code: 
    Sub Demo()
        Const 
    WD " CC "
              
    SP Split("A B CC C D CC E F CC G ACC H CC I J CCB K CC L"WD)
        
    MsgBox "Number of  «" WD "»  :   " UBound(SP)
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 06-14-2015 at 12:45 PM. Reason: optimizing …

  5. #5
    Registered User
    Join Date
    05-21-2013
    Location
    germany
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Parsing the XML files with VBA

    I have the following code and I want to fetch the 'Material' on the webpage which is inside the Innertext after tag:

    <div style="position:relative;">
    <div></div>
    <table id="list-table" width="100%" tabindex="1" cellspacing="0" cellpadding="0" border="0" role="grid" aria-multiselectable="false" aria-labelledby="gbox_list-table" class="ui-jqgrid-btable" style="width: 930px;">
    <tbody>
    <tr class="jqgfirstrow" role="row" style="height:auto">
    <td ...</td>
    <td ...</td>
    </tr>
    <tr role="row" id="1" tabindex="-1" class="ui-widget-content jqgrow ui-row-ltr">
    <td ...</td>
    <td ...</td>
    </tr>
    <tr role="row" id="2" tabindex="-1" class="ui-widget-content jqgrow ui-row-ltr">
    <td ...</td>
    <td ...</td>
    </tr>
    <tr role="row" id="3" tabindex="-1" class="ui-widget-content jqgrow ui-row-ltr">
    <td ...</td>
    <td ...</td>
    </tr>
    <tr role="row" id="4" tabindex="-1" class="ui-widget-content jqgrow ui-row-ltr">
    <td ...</td>
    <td ...</td>
    </tr>
    <tr role="row" id="5" tabindex="-1" class="ui-widget-content jqgrow ui-row-ltr">
    <td ...</td>
    <td ...</td>
    </tr>
    <tr role="row" id="6" tabindex="-1" class="ui-widget-content jqgrow ui-row-ltr">
    <td ...</td>
    <td ...</td>
    </tr>
    <tr role="row" id="7" tabindex="-1" class="ui-widget-content jqgrow ui-row-ltr">
    <td role="gridcell" style="padding-left:10px" title="Material" aria-describedby="list-table_">Material</td>
    <td role="gridcell" style="" title="600D polyester." aria-describedby="list-table_">600D polyester.</td>
    </tr>
    <tr ...>
    </tr>
    </tbody>
    </table> </div>

  6. #6
    Registered User
    Join Date
    05-21-2013
    Location
    germany
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Parsing the XML files with VBA

    I have the following code and I want to fetch the 'Material' on the webpage which is inside the Innertext after tag:

    <div style="position:relative;">
    <div></div>
    <table id="list-table" width="100%" tabindex="1" cellspacing="0" cellpadding="0" border="0" role="grid" aria-multiselectable="false" aria-labelledby="gbox_list-table" class="ui-jqgrid-btable" style="width: 930px;">
    <tbody>
    <tr class="jqgfirstrow" role="row" style="height:auto">
    <td ...</td>
    <td ...</td>
    </tr>
    <tr role="row" id="1" tabindex="-1" class="ui-widget-content jqgrow ui-row-ltr">
    <td ...</td>
    <td ...</td>
    </tr>
    <tr role="row" id="2" tabindex="-1" class="ui-widget-content jqgrow ui-row-ltr">
    <td ...</td>
    <td ...</td>
    </tr>
    <tr role="row" id="3" tabindex="-1" class="ui-widget-content jqgrow ui-row-ltr">
    <td ...</td>
    <td ...</td>
    </tr>
    <tr role="row" id="4" tabindex="-1" class="ui-widget-content jqgrow ui-row-ltr">
    <td ...</td>
    <td ...</td>
    </tr>
    <tr role="row" id="5" tabindex="-1" class="ui-widget-content jqgrow ui-row-ltr">
    <td ...</td>
    <td ...</td>
    </tr>
    <tr role="row" id="6" tabindex="-1" class="ui-widget-content jqgrow ui-row-ltr">
    <td ...</td>
    <td ...</td>
    </tr>
    <tr role="row" id="7" tabindex="-1" class="ui-widget-content jqgrow ui-row-ltr">
    <td role="gridcell" style="padding-left:10px" title="Material" aria-describedby="list-table_">Material</td>
    <td role="gridcell" style="" title="600D polyester." aria-describedby="list-table_">600D polyester.</td>
    </tr>
    <tr ...>
    </tr>
    </tbody>
    </table> </div>

  7. #7
    Registered User
    Join Date
    05-21-2013
    Location
    germany
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Parsing the XML files with VBA

    code is:

    Sub ParseMaterial()

    Dim Cell As Integer
    Dim ItemNbr As String

    Dim AElement As Object
    Dim AElements As IHTMLElementCollection
    Dim IE As MSXML2.XMLHTTP60
    Set IE = New MSXML2.XMLHTTP60

    Dim HTMLDoc As MSHTML.HTMLDocument
    Dim HTMLBody As MSHTML.HTMLBody

    Set HTMLDoc = New MSHTML.HTMLDocument
    Set HTMLBody = HTMLDoc.body

    For Cell = 1 To 5 'I iterate through the file row by row

    ItemNbr = Cells(Cell, 3).Value 'ItemNbr isin the 3rd Column of my spreadsheet

    IE.Open "GET", "http://www.example.com/?item=" & ItemNbr, False
    IE.send

    While IE.ReadyState <> 4
    DoEvents
    Wend

    HTMLBody.innerHTML = IE.responseText

    Set AElements = HTMLDoc.getElementById("list-table").getElementsByTagName("tr")
    For Each AElement In AElements
    If AElement.Title = "Material" Then
    Cells(Cell, 14) = AElement.nextNode.value 'I write the material in the 14th column
    End If
    Next AElement

    Application.Wait (Now + TimeValue("0:00:2"))

    Next Cell
    end sub



    Into: it does not work

  8. #8
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Parsing the XML files with VBA


    First, you must respect forum rules by using code tags …

    Seems too to be far away from thread title !

    Could you explain ? (but in a crystal clear way !)
    Best with the real URL …

  9. #9
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Parsing the XML files with VBA

    Also, please start a new thread
    Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.

  10. #10
    Registered User
    Join Date
    05-21-2013
    Location
    germany
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Parsing the XML files with VBA

    hi,

    what is rule 2?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Parsing XMLs in Excel (500 Files)
    By NeedForExcel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-19-2015, 02:05 AM
  2. Parsing/Separating Excel Worksheet into Multiple Output Files
    By Obibielebongnobi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-11-2014, 03:30 PM
  3. [SOLVED] Parsing out file into multiple new files
    By ktalamantez in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-26-2013, 02:07 AM
  4. Parsing out file into multiple new files
    By CrystalNewb in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-17-2009, 02:34 PM
  5. Parsing Huge Files of Text
    By ajocius in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-06-2005, 08:45 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1