Group data from text file

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
<org.m5.api.v1.Response....         >

<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.
                ' Display to console.
                ' Read in the next line.
                line = r.ReadLine
        End Using

Open in new window

Who is Participating?
Luis PérezConnect With a Mentor Software Architect in .NetCommented:
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
        'Clear the text
        text = String.Empty
    End If
    ' Read in the next line.
    line = r.ReadLine

Open in new window

Hope that helps.
lrbristerAuthor Commented:
Perfect. Thanks
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.