Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Group data from text file

Posted on 2013-06-07
2
Medium Priority
?
385 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 25

Accepted Solution

by:
Luis Pérez earned 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

609 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