本文介绍了Linq to XML检查空结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果xml文件中存在数据,则以下代码有效.但是,它们不存在datafield.tag.value("90")的时间.如何检查空结果.
例子

The following code works if data exist in the xml file. However, their times when datafield.tag.value("90") doesn’t exist. How can I check for null results.
example

if Num090 = Null then
Num090 = empty string



感谢你的帮助.



Appreciate your help.

Dim xd As XElement = XElement.Load(strFilename)
Dim strPipe As String = Chr(124)
Dim strSpace As String = Chr(10)
Dim strFinalString As String = ""
Dim Records = (From datafields In xd.Descendants("record") Select datafields)
For Each ser As XElement In Records
     Try
           Dim Num090 = (From datafield In ser.Descendants("datafield") Where (datafield.Attribute("tag").Value = "090")
           Select datafield.Elements.ElementAt(0))

           Dim DTIC856 = (From datafield In ser.Descendants("datafield") Where (datafield.Attribute("tag").Value = "856")
           Select datafield).Skip(1).First()


     Catch ex As Exception

     Finally

     End Try

Next

推荐答案

If Num90 Is Nothing Then
  Num90=String.Empty
End If



这篇关于Linq to XML检查空结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 07:37