Hi,
I am currently trying to read all node values from an xml document. I get all the values with the correct values but the way i want to write back to my csv and datatable is where I am having problems.
Below is my code:
Dim reader As XmlTextReader = New XmlTextReader("C:\ftp\upload\sessions.xml")
Dim logwriter As New StringBuilder
Dim table As New DataTable
table.Columns.Add("Report", GetType(String))
table.Columns.Add("Session", GetType(String))
table.Columns.Add("Visitor", GetType(String))
table.Columns.Add("ip", GetType(String))
table.Columns.Add("agent", GetType(String))
table.Columns.Add("host", GetType(String))
table.Columns.Add("chatReferer", GetType(String))
table.Columns.Add("GeoInfo", GetType(String))
table.Columns.Add("Chat", GetType(String))
table.Columns.Add("line", GetType(String))
table.Columns.Add("Text", GetType(String))
table.Columns.Add("HTML", GetType(String))
Do While (reader.Read())
Select Case reader.NodeType
Case XmlNodeType.Element
Console.Write("<" + reader.Name)
If reader.HasAttributes Then
While reader.MoveToNextAttribute()
Console.Write(" {0}='{1}'", reader.Name, reader.Value)
logwriter.Append(reader.Value + ","c)
End While
End If
Console.WriteLine(">")
Case XmlNodeType.Text
Console.WriteLine(reader.Value)
logwriter.AppendLine(reader.Value + ","c)
Case XmlNodeType.EndElement
Console.Write("br mode="hold" /> Console.WriteLine(">")
End Select
Loop
Using LOG As New StreamWriter("C:\ftp\upload\XMLTEST.csv")
LOG.WriteLine(logwriter.ToString)
'dt.ToString()
logwriter = Nothing
LOG.Dispose()
LOG.Close()
End Using
the way I want it in the datatable and csv is that colum 1 must contain repetitive data all the way down till the end of the xml parent node. The second colum must contain the value of the 2nd node and so on to make it into a hierarchy table with one to many relationship.
so for example:
ParentNode Value
info 2013-10-22T08:36:22+00:00 You are now connected with Amelia
Amelia 2013-10-22T08:36:29+00:00 ID48
You 2013-10-22T08:37:07+00:00 leanne
Amelia 2013-10-22T08:37:32+00:00 ID48
You 2013-10-22T08:37:47+00:00 very well thanks
Is there anyway of doing this?