I have found
2 different solutions.
Solution 1 :
Imports System.IO
Imports System.Xml
Imports System.Net
Public Class Form1
WithEvents bs As New BindingSource
Dim paths As String = Application.StartupPath + "/eeeror.log"
Dim source As String = File.ReadAllText(paths)
Dim paths1 As String = Application.StartupPath + "/123.log"
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
File.Delete(paths1)
If Not File.Exists(paths1) Then
File.Create(paths1).Dispose()
End If
Dim ds As New DataSet
Dim sr As System.IO.StringReader = New System.IO.StringReader(source)
ds.ReadXml(sr, XmlReadMode.InferSchema)
bs.DataSource =
(
From T In ds.Tables("item")
Select New Item With
{
.Description = T.Field(Of String)("description").Trim,
.Link = T.Field(Of String)("link").Trim,
.Title = T.Field(Of String)("title").Trim
}
).ToList
For Each i As Item In bs
Next
ds = Nothing
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim intITEMS As Integer = -1
For Each itemint As Item In bs
intITEMS += 1
MsgBox(intITEMS.ToString)
Dim item As Item = CType(bs.Item(intITEMS), Item)
File.AppendAllText(paths1, item.Title + ":" + item.Link + ":" + item.Description + vbCrLf)
Next
End Sub
End Class
Public Class Item
Public Property Title As String
Public Property Link As String
Public Property Description As String
Public Sub New()
End Sub
Public Overrides Function ToString() As String
Return String.Concat(Title, ", ", Description, ", ", Link)
End Function
End Class
This way, you get the number of lines in the 123.log file = items in rss. There will be no errors.
Solution 2 :
Imports System.IO
Imports System.Xml
Imports System.Net
Imports System.Text.RegularExpressions
Public Class Form1
Dim paths As String = Application.StartupPath + "/eeeror.log"
Dim source As String = File.ReadAllText(paths)
Dim paths1 As String = Application.StartupPath + "/123.log"
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
File.Delete(paths1)
If Not File.Exists(paths1) Then
File.Create(paths1).Dispose()
End If
Dim xmlString As String = My.Computer.FileSystem.ReadAllText(paths)
Using reader As XmlReader = XmlReader.Create(New StringReader(xmlString))
Dim itemcount As Integer = Regex.Matches(source, "<item>").Count
For i As Integer = 1 To itemcount + 1
Dim title As String = ""
Dim link As String = ""
Dim description As String = ""
reader.ReadToFollowing("title")
title = reader.ReadElementContentAsString
reader.ReadToFollowing("link")
link = reader.ReadElementContentAsString
reader.ReadToFollowing("description")
description = reader.ReadElementContentAsString
File.AppendAllText(paths1, title + ":" + link + ":" + description + vbCrLf)
Next
End Using
End Sub
End Class</items></item>
This will be giving you, 123.log = number of items + 1 as it also counts the title, description, link of the item. its not that reliable when you are looking to count more different elements as some elements may not be there 11 times and it could throw a error as well as mix up the data
you get the data in this format,
title:link:Description
which you can use readalllines functions and then separate the text through ':'. Here is a c# code for separating which i wrote for my old program,
string[] strArray = File.ReadAllLines(proxyDB);
int num = 0;
if (strArray.Length >= 1)
{
this.proxy_list = new string[strArray.Length];
foreach (string str in strArray)
{
string[] strArray3 = str.Split(new char[] { ':' });
this.proxy_list[num++] = str;
string proxy = strArray3(0)
string pass = strArray3(1)
}
}
This way you can specify them in listview, or anyway you want inside the foreach.