易截截图软件、单文件、免安装、纯绿色、仅160KB

判断xml的一个节点是否存在 - .NET技术 / VB.NET

我现在要读一个xml文件的一个节点值,但有时候这个节点可能不存在,这个时候我要新建这个节点并给它赋值。
所以问一下 如何判断xml的节点是存在还是不存在?
谢谢大家


不会。net,帮顶

C# code:

System.Xml.XmlNode node = xmlDoc.SelectSingleNode("root/" + key); //key节点
if (node == null){
//不存在
}



引用

C# code

System.Xml.XmlNode node = xmlDoc.SelectSingleNode("root/" + key); //key节点
if (node == null){
//不存在
}


c#的我知道,可是vb.net是怎么表示的?

Assembly code:
Dim node As System.Xml.XmlNode = xmlDoc.SelectSingleNode("root/" & key)
'key节点
If node Is Nothing Then
'不存在
End If


VB.NET code:
Dim node As System.Xml.XmlNode = xmlDoc.SelectSingleNode("root/" & key)
'key节点
If node Is Nothing Then
'不存在
End If


Dim node As System.Xml.XmlNode = xmlDoc.SelectSingleNode("//Root/A[@id=" & id & "]")
If node IsNot Nothing Then
End If

为了问问题,
先的赚赚


相关问答:

vb - VB / 基础类

我想把word另存为xml之后,用vb读取这个xml的内容,请问如何实现?
dim f as integer
dim b() as byte
dim s as string
dim L as long
f=freefile()
open "abc.xml" for binary access read as #f
......

vb读取用word转换成的xml里的数据 - VB / 基础类

Private Sub Command1_Click()
Dim MyString() As String
Open "a.xml" For Binary As #1 ' 打开刚创建的文件。
ReDim MyString(LOF(1) - 1)
  Put #1, , MyRecord ' 读入所有字符到变量中 ......

vb - VB / 基础类

数据库里有一个字段的内容是二进制,怎么才能把这个二进制读出来
使用字节流对象可以实现

例如现在数据库里有个字段的内容是0x504B03040A0000000800407F263C3B02465390000000820000000A0000006273CECACCE22E7478 ......

vb - VB / 非技术类

怎么把已知的数据保存成xml文件,现在已知的数据是
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
 xmlns:o=& ......

vb读取xml - VB / 基础类

现在有个xml文件是<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
 xm ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号