If your goal is to get these data to a CSV file then I would go over a DataTable. First read your XML into a DataTable, then export it to a CSV file. Your XML file is very near to the structure which could easily imported into a DataTable. The required structure is like this:
<root>
<record>
<field1>Some Data</field1>
<field2>Some other Data</field2>
<field3>42</field3>
...
</record>
<record>
<field1>...</field1>
<field2>...</field2>
<field3>...</field3>
...
</record>
</root>
So you should get rid of the unnecessary tag "baseExtraData". If you can influence the creating of the xml, very good. Else, some XSLT should do the job. Put this in a file with a name like "removebaseExtraData.xslt":
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<!-- Standard copy template: for all node where's no other rule: copy as they are -->
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<!-- The node will be deleted and the included nodes drawn one level upwards -->
<xsl:template match="baseExtraData">
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>
And here is the function to execute the XSLT:
Imports System.IO
Imports System.Xml
Public Sub XSLTTransform(ByVal XMLFile As String,
ByVal StylesheetFile As String,
Optional ByVal ResultFile As String = vbNullString)
Dim XSLT As New Xsl.XslCompiledTransform(True)
Dim SelfTransform As Boolean = (ResultFile = vbNullString)
' Load style sheet
Try
XSLT.Load(StylesheetFile)
Catch ex As Exception
Debug.Print(ex.Source & ": " & ex.Message)
Exit Sub
End Try
' Do the transform.
Try
If SelfTransform Then ResultFile = Path.GetTempFileName
XSLT.Transform(XMLFile, ResultFile)
If SelfTransform Then
File.Delete(XMLFile)
File.Move(ResultFile, XMLFile)
End If
Catch ex As Exception
Debug.Print(ex.Source & ": " & ex.Message)
End Try
End Sub
Now you should have something like this:
<?xml version="1.0" encoding="UTF-8"?>
<eventLog>
<event>
<type>access1</type>
<sample>Bone</sample>
<age>65</age>
</event>
<event>
<type>access2</type>
<sample>Malow</sample>
<age>11</age>
</event>
</eventLog>
The next step is easy:
Imports System.Xml
Dim XmlFile As XmlReader = XmlReader.Create(MyWorkfile, New XmlReaderSettings())
Dim DS As New DataSet
DS.ReadXml(XmlFile)
XmlFile.Close()
Dim MyDataTable As DataTable = DS.Tables(0)
Here MyWorkfile is the path of your (meanwhile modified) XML file and MyDataTable is your DataTable. This should now be easily exported to CSV. I haven't done this yet, so I cant give you one of my tested code. But there are plenty solutions in the net to do this task, maybe one of these links could help (I googled for "vb.net datatable to csv"):
DataTable to File
Most efficient way of converting a DataTable to CSV (C#)
http://www.devx.com/vb2themax/Tip/19703