下面的代碼給了我適合。我刪除了多餘的行李,只發布相關部分。在字段vb.net中讀取沒有值的xml文件
sQuickPath = Server.MapPath("~/App_Data/BillCalculator.xml")
Dim xrXMLReader As XmlReader = XmlReader.Create(sQuickPath)
While xrXMLReader.Read()
If xrXMLReader.NodeType = XmlNodeType.Element And xrXMLReader.Name = "ServiceType" Then
Dim ql As XElement = CType(XNode.ReadFrom(xrXMLReader), XElement)
If IsDBNull(ql.Element("ProposedCustomerCharge").Value) Then
ProposedCustomerCharge = 0.0
ElseIf IsNothing(ql.Element("ProposedCustomerCharge").Value) Then 'Check doesn't find empty element
ProposedCustomerCharge = 0.0
ElseIf ql.Element("ProposedCustomerCharge").Value Is Nothing Then
ProposedCustomerCharge = 0.0
Else
ProposedCustomerCharge = CType(ql.Element("ProposedCustomerCharge").Value, Double) 'blows chunks
End If
End If
End While
xrXMLReader.Close()
xrXMLReader = Nothing
我已經想盡辦法,我能想到的零出ProposedCustomerCharge的值時XML字段沒有價值,但IsNothing和是Nothing目前還沒有找到空字段值。
在XML文件中的字段如下所示:
<ProposedCustomerCharge></ProposedCustomerCharge>
如何找到空場?