Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VB.Net XMLReader检查值是否为空_Xml_Vb.net_Datagridview - Fatal编程技术网

VB.Net XMLReader检查值是否为空

VB.Net XMLReader检查值是否为空,xml,vb.net,datagridview,Xml,Vb.net,Datagridview,我想创建一个程序,它读取xml文件并将获得的值放入DataGridView。 此XML文件是MySQL数据库中的表转储。在这个表中,我有一个“set”列,在这里我可以选择一些选项。下面是一个没有选择选项的示例 <size></size> 当大小标记之间有一些数据时,读取没有问题,但如果没有数据,则它将不读取任何内容,因此我不会收到“无数据”。我该如何解决这个问题?提前谢谢你的帮助。亲切的问候 好吧,我得重写我的算法。我的xml文件包含此格式的数据 <?xml ve

我想创建一个程序,它读取xml文件并将获得的值放入DataGridView。 此XML文件是MySQL数据库中的表转储。在这个表中,我有一个“set”列,在这里我可以选择一些选项。下面是一个没有选择选项的示例

<size></size>

当大小标记之间有一些数据时,读取没有问题,但如果没有数据,则它将不读取任何内容,因此我不会收到“无数据”。我该如何解决这个问题?提前谢谢你的帮助。亲切的问候

好吧,我得重写我的算法。我的xml文件包含此格式的数据

<?xml version="1.0" standalone="yes"?>
 <RECORDS>
  <RECORD>
   <customerID>101</customerID>
   <name>Gall Anonim</name>
   <item>t-shirt</item>
   <size></size>
   ...
  </RECORD>
 </RECORDS>
问题解决了

    Dim ofile As New OpenFileDialog
    If ofile.ShowDialog = Windows.Forms.DialogResult.OK Then
        Dim reader As XmlTextReader = New XmlTextReader(ofile.FileName)
        Using reader
            Dim toadd As String = Nothing
            Dim str() As String
            Do While (reader.Read())
                Select Case reader.NodeType
                    Case XmlNodeType.Element
                        If reader.Name.ToLower.Contains("oldIndex") Then
                            Exit Select
                        End If
                    Case XmlNodeType.Text
                        If Not reader.Value = vbNullString Or Not reader.Value = vbNullChar Then
                            toadd = toadd & reader.Value & vbTab
                        Else
                            toadd = toadd & "no data" & vbTab
                        End If
                    Case XmlNodeType.EndElement
                        If reader.Name.Contains("RECORD") Then
                            If toadd IsNot Nothing Then
                                str = toadd.Split(vbTab)
                                ShopTable.Rows.Add(str)
                                toadd = Nothing
                            End If
                        End If
                End Select
            Loop
        End Using
    End If
<?xml version="1.0" standalone="yes"?>
 <RECORDS>
  <RECORD>
   <customerID>101</customerID>
   <name>Gall Anonim</name>
   <item>t-shirt</item>
   <size></size>
   ...
  </RECORD>
 </RECORDS>
Dim ofile As New OpenFileDialog
If ofile.ShowDialog = Windows.Forms.DialogResult.OK Then
    Dim sr As New System.IO.StreamReader(ofile.FileName)
    Dim document As XDocument = XDocument.Parse(sr.ReadToEnd.ToString)
    Dim records = From record In document.Descendants("RECORD") _
                  Select New With _
                     { _
                        .cID = record.Element("customerID").Value, _
                        .name = Chr(&H22) & record.Element("name").Value & Chr(&H22), _
                        .item = record.Element("item").Value, _
                        .size = record.Element("size").Value _
                     }
    MsgBox(records.cID) 'shows customer id
    do some work with those variables
    ...
End If