08
Apr
09

[VB.Net] Parse MSN Logs

Little function for parsing MSN logs. They are structured in XML, so arnt too hard to read:

    Private Sub ParseMSNLogFile(ByVal Filename As String)
        ''Create our XML Reader
        Dim XML_Reader As New System.Xml.XmlTextReader(Filename)
        ''XML Headers
        XML_Reader.Read()
        XML_Reader.Read()
        XML_Reader.Read()
        XML_Reader.Read()
        XML_Reader.Read()
        ''Read Session Details
        Dim FirstSessionID = XML_Reader.GetAttribute("FirstSessionID")
        Dim LastSessionID = XML_Reader.GetAttribute("LastSessionID")
        ''Create Reading Loop
        While Not XML_Reader.EOF
            XML_Reader.Read()
            ''Get Message Date - Could alternatly get the DateTime attribute
            Dim MDate As String = XML_Reader.GetAttribute("Date")
            ''Get Message Time - Could alternatly get the DateTime attribute
            Dim MTime As String = XML_Reader.GetAttribute("Time")
            ''Get the ID of the current message
            Dim MSessionID As String = XML_Reader.GetAttribute("SessionID")
            XML_Reader.Read()
            XML_Reader.Read()
            ''Get the FriendlyName of the user who send the message
            Dim FromFriendlyName As String = XML_Reader.GetAttribute("FriendlyName")
            XML_Reader.Read()
            XML_Reader.Read()
            XML_Reader.Read()
            ''Get the FriendlyName of the user who recieved the message
            Dim ToFriendlyName As String = XML_Reader.GetAttribute("FriendlyName")
            XML_Reader.Read()
            XML_Reader.Read()
            ''Get the style of the message (Fonts & colours)
            Dim MStyle As String = XML_Reader.GetAttribute("Style")
            ''Get the messages content
            Dim MText As String = XML_Reader.ReadString
            XML_Reader.Read()
        End While
    End Sub

That function in effects, does nothing other than read the file. It outputs nothing, and does not handle multi-person conversations.
Check back for an example usage in a program in a bit.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: