If I'm importing data such as this it will not work.
Debug also shows
"A first chance exception of type 'System.Xml.XmlException' occurred in System.Xml.dll"
<?xml version="1.0" encoding="utf-8" ?>
<XMLDocument>
<Books>
<Book>
<row id="0">
<data_rate_in_as_string>0B</data_rate_in_as_string>
<data_rate_out_as_string>0B</data_rate_out_as_string>
<downloaded_as_string>956.6MB</downloaded_as_string>
<elapsed_as_string>174d2h48m49s</elapsed_as_string>
</row>
</Book>
<Book>
<row id="1">
<data_rate_in_as_string>0B</data_rate_in_as_string>
<data_rate_out_as_string>0B</data_rate_out_as_string>
<downloaded_as_string>956.6MB</downloaded_as_string>
<elapsed_as_string>174d2h48m49s</elapsed_as_string>
</row>
</Book>
</Books>
</XMLDocument>
However if I removed the row ids completely it will work and I can import my data. I want to keep my row ids however and I also would like to add them to my datagridview too.
This is the project code as so far if it helps.
Public Shared Function EmptyStringToNull(o As String) As Object
Dim ret As Object = DBNull.Value
Try
If o.Trim.Length = 0 Then
ret = DBNull.Value
Else
ret = o
End If
Catch ex As Exception
End Try
Return ret
End Function
Private Sub ReadXMLFile()
Dim xmlDoc As New System.Xml.XmlDocument
Dim root As XmlElement = Nothing
Dim nodes As XmlNodeList = Nothing
Dim node As XmlNode = Nothing
Dim xmlFile As String = ""
Try
OpenFileDialog1.ShowDialog()
xmlFile = OpenFileDialog1.FileName
xmlDoc.Load(xmlFile)
root = xmlDoc.DocumentElement
nodes = root.SelectNodes("//XMLDocument/Books/Book/") 'The XMLPath
'nodes = root.SelectNodes("//result/data/row") 'The XMLPath
Me.DataGridView1.Rows.Clear() 'Clear Grid
For Each node In nodes
Me.DataGridView1.Rows.Add(EmptyStringToNull(node("rowid").InnerText),
EmptyStringToNull(node("data_rate_in_as_string").InnerText),
EmptyStringToNull(node("data_rate_out_as_string").InnerText),
EmptyStringToNull(node("downloaded_as_string").InnerText),
EmptyStringToNull(node("elapsed_as_string").InnerText))
Next
Catch ex As Exception
End Try
End Sub