如何判断XmlNode是否包含特定属性值?

2026-05-08 11:393阅读0评论SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计226个文字,预计阅读时间需要1分钟。

如何判断XmlNode是否包含特定属性值?

在Sub中添加if条件判断,若属性TEST不等于test.doc的xml节点STORE不存在时执行。建议使用VB编写,以下代码示例:

vbSub CheckNode() Dim doc As XmlDocument Dim City As XmlNode

' 创建XML文档对象 Set doc=New XmlDocument ' 加载XML文件 doc.Load(test.doc)

' 检查TEST属性是否等于test.doc If doc.DocumentElement.Attributes(TEST).Value test.doc Then ' 检查STORE节点是否存在 Set City=doc.SelectSingleNode(//STORE) If City Is Nothing Then ' 执行相关操作 ' ... End If End IfEnd Sub

我想在sub中放置一个if条件,告诉它在属性TEST =“test.doc”的xml节点STORE不存在时运行.任何建议都会很棒.我是vb的新手.

如何判断XmlNode是否包含特定属性值?

Sub InsertNode(ByVal doc As XmlDocument) Dim City As XmlNode = doc.DocumentElement Dim Location As XmlElement = doc.CreateElement("store") Location.SetAttribute("test", "test.doc") Dim books As XmlElement = doc.CreateElement("books") books.InnerXml = "New Words" Location.AppendChild(books) City.AppendChild(store) End Sub 'InsertNode

XML文件的示例

<city> <store test="test.doc"> <books> "New Words" </books> </store> </city> 尝试类似的东西:

If Not doc.SelectSingleNode("//store[@test='test.doc']") Is Nothing Then Exit Sub End If

本文共计226个文字,预计阅读时间需要1分钟。

如何判断XmlNode是否包含特定属性值?

在Sub中添加if条件判断,若属性TEST不等于test.doc的xml节点STORE不存在时执行。建议使用VB编写,以下代码示例:

vbSub CheckNode() Dim doc As XmlDocument Dim City As XmlNode

' 创建XML文档对象 Set doc=New XmlDocument ' 加载XML文件 doc.Load(test.doc)

' 检查TEST属性是否等于test.doc If doc.DocumentElement.Attributes(TEST).Value test.doc Then ' 检查STORE节点是否存在 Set City=doc.SelectSingleNode(//STORE) If City Is Nothing Then ' 执行相关操作 ' ... End If End IfEnd Sub

我想在sub中放置一个if条件,告诉它在属性TEST =“test.doc”的xml节点STORE不存在时运行.任何建议都会很棒.我是vb的新手.

如何判断XmlNode是否包含特定属性值?

Sub InsertNode(ByVal doc As XmlDocument) Dim City As XmlNode = doc.DocumentElement Dim Location As XmlElement = doc.CreateElement("store") Location.SetAttribute("test", "test.doc") Dim books As XmlElement = doc.CreateElement("books") books.InnerXml = "New Words" Location.AppendChild(books) City.AppendChild(store) End Sub 'InsertNode

XML文件的示例

<city> <store test="test.doc"> <books> "New Words" </books> </store> </city> 尝试类似的东西:

If Not doc.SelectSingleNode("//store[@test='test.doc']") Is Nothing Then Exit Sub End If