neo21
03-06-2012, 23:24
Доброго времени суток.
Есть XML файл:
<?xml version="1.0" encoding="windows-1251"?>
<document>
<data>
<next1>777</next1>
<next2>888</next2>
<next3>999</next3>
<next4 ROWNUM="1">1</next4>
<next4 ROWNUM="2">2</next4>
<next4 ROWNUM="3">3</next4>
<next4 ROWNUM="4">4</next4>
</data>
</document>
С помощью программы:
Код:
http://i.piccy.info/i7/7b616540e13d0826a5afa13b4eed30f6/1-5-8596/40128949/vopros.jpg
Imports System.Xml
Imports System.Data
Public Class Form1
#Region "XML"
Public Shared Function EmptyStringToNull(ByVal 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("//document/data") 'The XMLPath
Me.DataGridView1.Rows.Clear() 'Clear Grid
For Each node In nodes
Me.DataGridView1.Rows.Add(EmptyStringToNull(node("next1").InnerText), EmptyStringToNull(node("next2").InnerText), EmptyStringToNull(node("next3").InnerText), EmptyStringToNull(node("next4").InnerText))
Next
Catch ex As Exception
End Try
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ReadXMLFile()
End Sub
End Class
Я загружаю данные из XML файла в DataGridView1.
Как сделать, чтобы в столбец next4 грузились все данные:
<next4 ROWNUM="2">2</next4>
<next4 ROWNUM="3">3</next4>
<next4 ROWNUM="4">4</next4>
Есть XML файл:
<?xml version="1.0" encoding="windows-1251"?>
<document>
<data>
<next1>777</next1>
<next2>888</next2>
<next3>999</next3>
<next4 ROWNUM="1">1</next4>
<next4 ROWNUM="2">2</next4>
<next4 ROWNUM="3">3</next4>
<next4 ROWNUM="4">4</next4>
</data>
</document>
С помощью программы:
Код:
http://i.piccy.info/i7/7b616540e13d0826a5afa13b4eed30f6/1-5-8596/40128949/vopros.jpg
Imports System.Xml
Imports System.Data
Public Class Form1
#Region "XML"
Public Shared Function EmptyStringToNull(ByVal 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("//document/data") 'The XMLPath
Me.DataGridView1.Rows.Clear() 'Clear Grid
For Each node In nodes
Me.DataGridView1.Rows.Add(EmptyStringToNull(node("next1").InnerText), EmptyStringToNull(node("next2").InnerText), EmptyStringToNull(node("next3").InnerText), EmptyStringToNull(node("next4").InnerText))
Next
Catch ex As Exception
End Try
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ReadXMLFile()
End Sub
End Class
Я загружаю данные из XML файла в DataGridView1.
Как сделать, чтобы в столбец next4 грузились все данные:
<next4 ROWNUM="2">2</next4>
<next4 ROWNUM="3">3</next4>
<next4 ROWNUM="4">4</next4>