我的代码是这样的:
Using StateProv As XmlElement = CType(hotelSearch.SelectSingleNode("/ota:OTA_HotelSearchRQ/ota:Criteria/ota:Criterion/ota:Address/ota:StateProv", nsmgr), XmlElement) 'i am getting error in this line....
StateProv.SetAttribute("StateCode", BLLHotel_Search.StateCode)
StateProv.ChildNodes(0).InnerText = BLLHotel_Search.StateName
End Using
error:
"using operand of type 'System.xml.xmlelement' must implement 'system.idisposable'"
答案 0 :(得分:1)
您无需使用使用
试试
Dim StateProv As XmlElement = CType(hotelSearch.SelectSingleNode("/ota:OTA_HotelSearchRQ/ota:Criteria/ota:Criterion/ota:Address/ota:StateProv", nsmgr), XmlElement) 'i am getting error in this line....
StateProv.SetAttribute("StateCode", BLLHotel_Search.StateCode)
StateProv.ChildNodes(0).InnerText = BLLHotel_Search.StateName
使用
的文档使用关键字:
作为陈述, 当它在末尾定义范围时 一个物体将被处置。
检查是否有值将其与Nothing
Dim node As XmlNode = doc.SelectSingleNode("//")
If node IsNot Nothing Then
Dim attribute As XmlAttribute = node.Attributes(0)
End If
试试这个
Dim StateProv As XmlElement = CType(hotelSearch.SelectSingleNode("/ota:OTA_HotelSearchRQ/ota:Criteria/ota:Criterion/ota:Address/ota:StateProv", nsmgr), XmlElement)
If StateProv IsNot Nothing Then
StateProv.SetAttribute("StateCode", BLLHotel_Search.StateCode)
StateProv.ChildNodes(0).InnerText = BLLHotel_Search.StateName
End If