如何检查节点是否存在以及VB.NET中是否有字符串值? [英] How do I check if a node exist and if it has a string value in VB.NET?

查看:117
本文介绍了如何检查节点是否存在以及VB.NET中是否有字符串值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查元素是否存在以及是否有字符串值。



 <   AddressName  > 我的地址<   / AddressName  >  





我如何检查vb.net是否存在此元素以及是否有字符串值。



我尝试了什么:



 如果  AddressNameNode   没有 然后 

解决方案

正如文档所述,您可以使用2个类:

XDocument类(System.Xml.Linq) [ ^ ]

XmlDocument Class(System.Xml) [ ^ ]



示例:

  Dim  xdoc  As  XDocument = XDocument.Load(rdr)
Dim ele = xdoc.Descendants( ParentOfAddressNameNode)。 _
其中(函数(x)x.Name = AddressName)。 _
选择功能(x)x)





欲了解更多详情,请阅读: .NET XML数据的语言集成查询 [ ^ ]


I would like to check if an element exist and if it has a string value.

<AddressName>My address</AddressName>



How can I check in vb.net if this element exist and if it has a string value.

What I have tried:

If Not AddressNameNode is nothing Then

解决方案

As the documentation states, you may use 2 classes:
XDocument Class (System.Xml.Linq)[^]
XmlDocument Class (System.Xml)[^]

Example:

Dim xdoc As XDocument = XDocument.Load(rdr)
Dim ele = xdoc.Descendants("ParentOfAddressNameNode"). _
        Where(Function(x) x.Name="AddressName"). _
        Select(Function(x) x)



For further details, please read this: .NET Language-Integrated Query for XML Data[^]


这篇关于如何检查节点是否存在以及VB.NET中是否有字符串值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆