Solved

Group data from text file

Posted on 2013-06-07
2
372 Views
Last Modified: 2013-06-07
I have a routine where I'm reading a text file into a list in the code below.

I need to modify this so that data is "grouped" based on starting and ending tags.

What I want is to group each xml block into one line
So...
<org.m5.api.v1.Response....         >
    <ErrorCount>0</ErrorCount>
    blah...blah...blah..
</org.m5.api.v1.Response>

Becomes
<org.m5.api.v1.Response><ErrorCount>0</ErrorCount>  blah..</org.m5.api.v1.Response>



        Dim list As New List(Of String)

        ' Open file.txt with the Using statement.
        Using r As StreamReader = New StreamReader("C:\temp\Output.txt")
            ' Store contents in this String.
            Dim line As String

            ' Read first line.
            line = r.ReadLine

            ' Loop over each line in file, While list is Not Nothing.
            Do While (Not line Is Nothing)
                ' Add this line to list.
                list.Add(line)
                'Me.ListBox1.Items.Add(line)
                ' Display to console.
                'Console.WriteLine(line)
                ' Read in the next line.
                line = r.ReadLine
            Loop
        End Using

Open in new window

0
Comment
Question by:lrbrister
2 Comments
 
LVL 25

Accepted Solution

by:
Luis Pérez earned 500 total points
ID: 39229261
Mmm... if all your end "parent" nodes follow a similar pattern (i.e. all of them contain the "org.m5" string), you can do something like this:

Dim text As String = String.Empty
Do While (Not line Is Nothing)
    text += line
    If line.StartsWith("</org.m5") Then 'Or "</org", if all of your "parent" nodes starts with "<org"
        'Add the line to the list
        Me.ListBox1.Items.Add(text)
        'Clear the text
        text = String.Empty
    End If
    ' Read in the next line.
    line = r.ReadLine
Loop

Open in new window

Hope that helps.
0
 

Author Closing Comment

by:lrbrister
ID: 39229467
Perfect. Thanks
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now